EditProfile
5 years ago
Login
3 years ago
MemberDirectory
7 months ago
PasswordReset
5 years ago
Registration
3 years ago
UserProfile
1 year ago
AbstractBuildScratch.php
7 months ago
AbstractMemberDirectoryTheme.php
4 months ago
AbstractTheme.php
11 months ago
FieldListing.php
7 months ago
MemberDirectoryListing.php
2 months ago
MemberDirectoryTrait.php
1 year ago
ProfileFieldListing.php
2 months ago
ThemeInterface.php
5 years ago
ThemesRepository.php
1 year ago
index.php
5 years ago
AbstractMemberDirectoryTheme.php
696 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Themes\DragDrop; |
| 4 | |
| 5 | use ProfilePress\Core\Classes\ExtensionManager as EM; |
| 6 | use ProfilePress\Core\Classes\PROFILEPRESS_sql; |
| 7 | use ProfilePress\Core\ShortcodeParser\Builder\FieldsShortcodeCallback; |
| 8 | use WP_User_Query; |
| 9 | |
| 10 | abstract class AbstractMemberDirectoryTheme extends AbstractTheme |
| 11 | { |
| 12 | use MemberDirectoryTrait; |
| 13 | |
| 14 | public function __construct($form_id, $form_type) |
| 15 | { |
| 16 | parent::__construct($form_id, $form_type); |
| 17 | |
| 18 | $this->initializeMemberDirectoryTrait($form_id, [ |
| 19 | 'users_per_page' => $this->get_default_result_number_per_page(), |
| 20 | 'user_roles' => array_filter($this->get_meta('ppress_md_user_roles')), |
| 21 | 'specific_users' => $this->get_meta('ppress_md_specific_users'), |
| 22 | 'exclude_users' => $this->get_meta('ppress_md_exclude_users'), |
| 23 | 'sort_default' => $this->get_meta('ppress_md_sort_default'), |
| 24 | 'search_fields' => $this->get_meta('ppress_md_search_fields') |
| 25 | ]); |
| 26 | |
| 27 | add_action('ppress_drag_drop_builder_admin_page', [$this, 'js_script']); |
| 28 | } |
| 29 | |
| 30 | abstract function form_wrapper_class(); |
| 31 | |
| 32 | abstract function directory_structure(); |
| 33 | |
| 34 | public function form_structure() |
| 35 | { |
| 36 | $wp_user_query = $this->wp_user_query(); |
| 37 | |
| 38 | $total_users_found = $wp_user_query['total_users_found']; |
| 39 | |
| 40 | $query_params = $this->search_filter_query_params(); |
| 41 | |
| 42 | ob_start(); |
| 43 | |
| 44 | printf('[pp-form-wrapper class="%s"]', $this->form_wrapper_class()); |
| 45 | |
| 46 | $this->search_filter_sort_structure(); |
| 47 | |
| 48 | if ( ! $this->is_result_after_search_enabled() || (isset($query_params['ppmd-search']) && $query_params['ppmd-search'] == $this->form_id)) { |
| 49 | |
| 50 | if (0 === $total_users_found) { ?> |
| 51 | |
| 52 | <div class="ppressmd-members-total-wrap"> |
| 53 | <div class="ppressmd-members-total"> |
| 54 | <?= $this->get_no_result_text() ?> |
| 55 | </div> |
| 56 | </div> |
| 57 | |
| 58 | <?php |
| 59 | |
| 60 | } else { |
| 61 | |
| 62 | if ( ! empty($query_params[$this->search_query_key()])) { ?> |
| 63 | |
| 64 | <div class="ppressmd-members-total-wrap"> |
| 65 | <div class="ppressmd-members-total"> |
| 66 | |
| 67 | <?= str_replace( |
| 68 | '{total_users}', $total_users_found, |
| 69 | $total_users_found > 1 ? $this->get_results_text() : $this->get_single_result_text() |
| 70 | ) ?> |
| 71 | </div> |
| 72 | </div> |
| 73 | |
| 74 | <?php |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | if ($total_users_found > 0) { |
| 79 | |
| 80 | $this->directory_structure(); |
| 81 | |
| 82 | $this->display_pagination( |
| 83 | $total_users_found, |
| 84 | $this->get_default_result_number_per_page() |
| 85 | ); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | echo '[/pp-form-wrapper]'; |
| 90 | |
| 91 | return ob_get_clean(); |
| 92 | } |
| 93 | |
| 94 | public function js_script() |
| 95 | { |
| 96 | ?> |
| 97 | <script type="text/javascript"> |
| 98 | (function ($) { |
| 99 | |
| 100 | var run = function () { |
| 101 | $('#ppress_md_enable_custom_sort').on('change', function () { |
| 102 | $('.ppress_md_sort_method_fields_wrap').toggle(this.checked); |
| 103 | }).trigger('change'); |
| 104 | |
| 105 | $('#ppress_md_enable_search').on('change', function () { |
| 106 | $('.ppress_md_search_fields_wrap').toggle(this.checked); |
| 107 | $('.ppress_md_enable_filters_wrap').toggle(this.checked); |
| 108 | $('.ppress_md_filter_fields_wrap').toggle(this.checked); |
| 109 | }).trigger('change'); |
| 110 | }; |
| 111 | |
| 112 | $(run); |
| 113 | |
| 114 | })(jQuery); |
| 115 | </script> |
| 116 | <?php |
| 117 | } |
| 118 | |
| 119 | public function default_metabox_settings() |
| 120 | { |
| 121 | $data = parent::default_metabox_settings(); |
| 122 | $data['ppress_md_user_roles'] = []; |
| 123 | $data['ppress_md_specific_users'] = ''; |
| 124 | $data['ppress_md_exclude_users'] = ''; |
| 125 | |
| 126 | $data['ppress_md_sort_default'] = 'newest'; |
| 127 | $data['ppress_md_enable_custom_sort'] = 'false'; |
| 128 | $data['ppress_md_sort_method_fields'] = []; |
| 129 | |
| 130 | $data['ppress_md_enable_search'] = 'true'; |
| 131 | $data['ppress_md_search_fields'] = [ |
| 132 | 'pp_email_address', |
| 133 | 'pp_website_url', |
| 134 | 'pp_display_name', |
| 135 | 'first_name', |
| 136 | 'last_name' |
| 137 | ]; |
| 138 | $data['ppress_md_enable_filters'] = 'false'; |
| 139 | $data['ppress_md_filter_fields'] = []; |
| 140 | |
| 141 | $data['ppress_md_enable_result_after_search'] = 'false'; |
| 142 | $data['ppress_md_result_number_per_page'] = '9'; |
| 143 | $data['ppress_md_results_text'] = sprintf(esc_html__('%s Members', 'wp-user-avatar'), '{total_users}'); |
| 144 | $data['ppress_md_single_result_text'] = sprintf(esc_html__('%s Member', 'wp-user-avatar'), '{total_users}'); |
| 145 | $data['ppress_md_no_result_text'] = esc_html__('We could not find any user that matches your search criteria', 'wp-user-avatar'); |
| 146 | |
| 147 | $data['ppress_md_search_filter_field_text_color'] = '#666666'; |
| 148 | $data['ppress_md_search_filter_field_border_color'] = '#dddddd'; |
| 149 | |
| 150 | $data['ppress_md_pagination_link_color'] = '#666666'; |
| 151 | $data['ppress_md_pagination_active_link_color'] = '#ffffff'; |
| 152 | $data['ppress_md_pagination_active_background_color'] = '#007bff'; |
| 153 | |
| 154 | return $data; |
| 155 | } |
| 156 | |
| 157 | public function appearance_settings($settings) |
| 158 | { |
| 159 | $settings[] = [ |
| 160 | 'id' => 'ppress_md_user_roles', |
| 161 | 'type' => 'select2', |
| 162 | 'label' => esc_html__('User Roles to Display', 'wp-user-avatar'), |
| 163 | 'description' => esc_html__('If you do not want to show all members, select the user roles to appear in this directory.', 'wp-user-avatar'), |
| 164 | 'options' => ppress_wp_roles_key_value(false), |
| 165 | 'priority' => 5 |
| 166 | ]; |
| 167 | |
| 168 | $settings[] = [ |
| 169 | 'id' => 'ppress_md_specific_users', |
| 170 | 'type' => 'textarea', |
| 171 | 'placeholder' => esc_html__('Example: 1, 6, 32', 'wp-user-avatar'), |
| 172 | 'label' => esc_html__('Comma Separated List of Users ID to Only Show', 'wp-user-avatar'), |
| 173 | 'priority' => 10 |
| 174 | ]; |
| 175 | |
| 176 | $settings[] = [ |
| 177 | 'id' => 'ppress_md_exclude_users', |
| 178 | 'type' => 'textarea', |
| 179 | 'placeholder' => esc_html__('Example: 1, 6, 32', 'wp-user-avatar'), |
| 180 | 'label' => esc_html__('Comma Separated List of Users ID to Exclude', 'wp-user-avatar'), |
| 181 | 'priority' => 10 |
| 182 | ]; |
| 183 | |
| 184 | return $settings; |
| 185 | } |
| 186 | |
| 187 | public function color_settings($settings) |
| 188 | { |
| 189 | $settings2 = [ |
| 190 | [ |
| 191 | 'id' => 'ppress_md_search_filter_field_text_color', |
| 192 | 'type' => 'color', |
| 193 | 'label' => esc_html__('Search & Filter Fields Text', 'wp-user-avatar') |
| 194 | ], |
| 195 | [ |
| 196 | 'id' => 'ppress_md_search_filter_field_border_color', |
| 197 | 'type' => 'color', |
| 198 | 'label' => esc_html__('Search & Filter Fields Border', 'wp-user-avatar') |
| 199 | ], |
| 200 | [ |
| 201 | 'id' => 'ppress_md_pagination_link_color', |
| 202 | 'type' => 'color', |
| 203 | 'label' => esc_html__('Pagination Links', 'wp-user-avatar') |
| 204 | ], |
| 205 | [ |
| 206 | 'id' => 'ppress_md_pagination_active_link_color', |
| 207 | 'type' => 'color', |
| 208 | 'label' => esc_html__('Pagination Active Link Color', 'wp-user-avatar') |
| 209 | ], |
| 210 | [ |
| 211 | 'id' => 'ppress_md_pagination_active_background_color', |
| 212 | 'type' => 'color', |
| 213 | 'label' => esc_html__('Pagination Active Link Background', 'wp-user-avatar') |
| 214 | ] |
| 215 | ]; |
| 216 | |
| 217 | return array_merge($settings, $settings2); |
| 218 | } |
| 219 | |
| 220 | public function metabox_settings($settings, $form_type, $DragDropBuilderInstance) |
| 221 | { |
| 222 | $sorting_options = [esc_html__('Standard Fields', 'wp-user-avatar') => $this->md_standard_sort_fields()]; |
| 223 | |
| 224 | $search_options = [ |
| 225 | esc_html__('Standard', 'wp-user-avatar') => [ |
| 226 | 'pp_email_address' => esc_html__('Email Address', 'wp-user-avatar'), |
| 227 | 'pp_website_url' => esc_html__('Website', 'wp-user-avatar'), |
| 228 | 'pp_display_name' => esc_html__('Display Name', 'wp-user-avatar'), |
| 229 | 'first_name' => esc_html__('First Name', 'wp-user-avatar'), |
| 230 | 'last_name' => esc_html__('Last Name', 'wp-user-avatar'), |
| 231 | 'description' => esc_html__('Biography', 'wp-user-avatar') |
| 232 | ] |
| 233 | ]; |
| 234 | |
| 235 | if (EM::is_enabled(EM::CUSTOM_FIELDS)) { |
| 236 | $cf_label = esc_html__('Custom Fields', 'wp-user-avatar'); |
| 237 | $sorting_options[$cf_label] = ppress_custom_fields_key_value_pair(true); |
| 238 | $search_options[$cf_label] = ppress_custom_fields_key_value_pair(true); |
| 239 | } |
| 240 | |
| 241 | $new_settings['ppress_md_sorting'] = [ |
| 242 | 'tab_title' => esc_html__('Sorting', 'wp-user-avatar'), |
| 243 | [ |
| 244 | 'id' => 'ppress_md_sort_default', |
| 245 | 'label' => esc_html__('Default Sorting method', 'wp-user-avatar'), |
| 246 | 'type' => 'select', |
| 247 | 'options' => $sorting_options |
| 248 | ], |
| 249 | [ |
| 250 | 'id' => 'ppress_md_enable_custom_sort', |
| 251 | 'label' => esc_html__('Enable custom sorting', 'wp-user-avatar'), |
| 252 | 'type' => 'checkbox', |
| 253 | ], |
| 254 | [ |
| 255 | 'id' => 'ppress_md_sort_method_fields', |
| 256 | 'label' => esc_html__('Sorting Method Fields', 'wp-user-avatar'), |
| 257 | 'type' => 'select2', |
| 258 | 'options' => $sorting_options, |
| 259 | 'description' => esc_html__('Fields to show in sorting dropdown menu', 'wp-user-avatar') |
| 260 | ], |
| 261 | ]; |
| 262 | |
| 263 | $new_settings['ppress_md_search'] = [ |
| 264 | 'tab_title' => esc_html__('Search', 'wp-user-avatar'), |
| 265 | [ |
| 266 | 'id' => 'ppress_md_enable_search', |
| 267 | 'label' => esc_html__('Display Search Form', 'wp-user-avatar'), |
| 268 | 'type' => 'checkbox' |
| 269 | ], |
| 270 | [ |
| 271 | 'id' => 'ppress_md_search_fields', |
| 272 | 'label' => esc_html__('Search Fields', 'wp-user-avatar'), |
| 273 | 'type' => 'select2', |
| 274 | 'options' => $search_options, |
| 275 | 'description' => esc_html__('Select fields to search in.', 'wp-user-avatar') |
| 276 | ] |
| 277 | ]; |
| 278 | |
| 279 | |
| 280 | if (EM::is_enabled(EM::CUSTOM_FIELDS)) { |
| 281 | |
| 282 | $new_settings['ppress_md_search'][] = [ |
| 283 | 'id' => 'ppress_md_enable_filters', |
| 284 | 'label' => esc_html__('Enable Filters', 'wp-user-avatar'), |
| 285 | 'type' => 'checkbox', |
| 286 | 'description' => esc_html__('If enabled, users will be able to filter members in this directory', 'wp-user-avatar') |
| 287 | ]; |
| 288 | |
| 289 | $new_settings['ppress_md_search'][] = [ |
| 290 | 'id' => 'ppress_md_filter_fields', |
| 291 | 'label' => esc_html__('Filter Fields', 'wp-user-avatar'), |
| 292 | 'type' => 'select2', |
| 293 | 'options' => array_reduce(PROFILEPRESS_sql::get_profile_custom_fields_by_types([ |
| 294 | 'select', |
| 295 | 'checkbox', |
| 296 | 'radio', |
| 297 | 'country', |
| 298 | 'date' |
| 299 | ]), function ($carry, $item) { |
| 300 | $carry[$item->field_key] = ppress_woocommerce_field_transform($item->field_key, $item->label_name); |
| 301 | |
| 302 | return $carry; |
| 303 | }, ['ppress_user_role' => esc_html__('User Role', 'wp-user-avatar')]), |
| 304 | 'description' => esc_html__('Select custom fields that members can be filtered by. Only Select, Checkbox, Radio, Country and Date/Time fields are supported.', 'wp-user-avatar') |
| 305 | ]; |
| 306 | } |
| 307 | |
| 308 | if ( ! EM::is_enabled(EM::CUSTOM_FIELDS)) { |
| 309 | $upgrade_url = 'https://profilepress.com/pricing/?utm_source=wp_dashboard&utm_medium=upgrade&utm_campaign=md_custom_field_upsell'; |
| 310 | $new_settings['ppress_md_search'][] = [ |
| 311 | 'id' => 'ppress_md_search_filter_upsell', |
| 312 | 'label' => '', |
| 313 | 'type' => 'custom', |
| 314 | 'content' => sprintf( |
| 315 | esc_html__('%sUpgrade to ProfilePress premium%s if you don\'t have the custom field addon so you can enable search and filtering by custom fields.', 'wp-user-avatar'), |
| 316 | '<a href="' . $upgrade_url . '" target="_blank">', '</a>' |
| 317 | ), |
| 318 | ]; |
| 319 | } |
| 320 | |
| 321 | $new_settings['ppress_md_result_pagination'] = [ |
| 322 | 'tab_title' => esc_html__('Result & Pagination', 'wp-user-avatar'), |
| 323 | [ |
| 324 | 'id' => 'ppress_md_enable_result_after_search', |
| 325 | 'label' => esc_html__('Show Results Only After a Search', 'wp-user-avatar'), |
| 326 | 'type' => 'checkbox', |
| 327 | 'description' => esc_html__('Enable to only show members after a search is performed', 'wp-user-avatar') |
| 328 | ], |
| 329 | [ |
| 330 | 'id' => 'ppress_md_result_number_per_page', |
| 331 | 'label' => esc_html__('Number of Members per Page', 'wp-user-avatar'), |
| 332 | 'type' => 'number' |
| 333 | ], |
| 334 | [ |
| 335 | 'id' => 'ppress_md_results_text', |
| 336 | 'label' => esc_html__('Results Text', 'wp-user-avatar'), |
| 337 | 'type' => 'text' |
| 338 | ], |
| 339 | [ |
| 340 | 'id' => 'ppress_md_single_result_text', |
| 341 | 'label' => esc_html__('Single Result Text', 'wp-user-avatar'), |
| 342 | 'type' => 'text' |
| 343 | ], |
| 344 | [ |
| 345 | 'id' => 'ppress_md_no_result_text', |
| 346 | 'label' => esc_html__('No Result Text', 'wp-user-avatar'), |
| 347 | 'type' => 'text' |
| 348 | ], |
| 349 | ]; |
| 350 | |
| 351 | return $new_settings; |
| 352 | } |
| 353 | |
| 354 | protected function search_filter_query_params() |
| 355 | { |
| 356 | static $cache = []; |
| 357 | |
| 358 | if ( ! isset($cache[$this->form_id])) { |
| 359 | |
| 360 | $query_params = []; |
| 361 | |
| 362 | if (empty($query_params) && ! empty($_GET['filter' . $this->form_id])) { |
| 363 | $query_params = json_decode(base64_decode($_GET['filter' . $this->form_id]), true); |
| 364 | } |
| 365 | |
| 366 | $cache[$this->form_id] = $query_params; |
| 367 | } |
| 368 | |
| 369 | return $cache[$this->form_id]; |
| 370 | } |
| 371 | |
| 372 | public function md_standard_sort_fields(): array |
| 373 | { |
| 374 | return [ |
| 375 | 'newest' => esc_html__('Newest Users First', 'wp-user-avatar'), |
| 376 | 'oldest' => esc_html__('Oldest Users First', 'wp-user-avatar'), |
| 377 | 'first-name' => esc_html__('First Name', 'wp-user-avatar'), |
| 378 | 'last-name' => esc_html__('Last Name', 'wp-user-avatar'), |
| 379 | 'username' => esc_html__('Username', 'wp-user-avatar') |
| 380 | ]; |
| 381 | } |
| 382 | |
| 383 | public function get_sort_field_label($field) |
| 384 | { |
| 385 | $pp_custom_fields = ppress_custom_fields_key_value_pair(true); |
| 386 | |
| 387 | return ppress_var($this->md_standard_sort_fields(), $field, ppress_var($pp_custom_fields, $field)); |
| 388 | } |
| 389 | |
| 390 | protected function sort_method_dropdown_menu() |
| 391 | { |
| 392 | $sortby_query_key = 'sortby' . $this->form_id; |
| 393 | |
| 394 | $custom_sort_enabled = $this->get_meta('ppress_md_enable_custom_sort') == 'true'; |
| 395 | |
| 396 | $default_sort_field = ppress_var($_GET, $sortby_query_key, $this->get_meta('ppress_md_sort_default'), true); |
| 397 | |
| 398 | $custom_sort_fields = array_filter($this->get_meta('ppress_md_sort_method_fields'), function ($item) use ($default_sort_field) { |
| 399 | return ! empty($item) && $item != $default_sort_field; |
| 400 | }); |
| 401 | |
| 402 | if ( ! $custom_sort_enabled || empty($custom_sort_fields)) return; |
| 403 | |
| 404 | ?> |
| 405 | <div class="ppressmd-member-directory-sorting"> |
| 406 | <span><?= esc_html__('Sort by', 'wp-user-avatar') ?>: </span> |
| 407 | <div class="ppressmd-member-directory-sorting-a"> |
| 408 | <a href=" <?= esc_url(add_query_arg([$sortby_query_key => $default_sort_field])) ?>" class="ppressmd-member-directory-sorting-a-text"> |
| 409 | <?= $this->get_sort_field_label($default_sort_field) ?> |
| 410 | <span class="ppress-material-icons">keyboard_arrow_down</span> </a> |
| 411 | |
| 412 | <div class="ppressmd-new-dropdown"> |
| 413 | <ul> |
| 414 | <?php foreach ($custom_sort_fields as $field) : ?> |
| 415 | <li> |
| 416 | <a href="<?= esc_url(add_query_arg([$sortby_query_key => $field])) ?>"> |
| 417 | <?= $this->get_sort_field_label($field) ?> |
| 418 | </a> |
| 419 | </li> |
| 420 | <?php endforeach; ?> |
| 421 | </ul> |
| 422 | </div> |
| 423 | </div> |
| 424 | </div> |
| 425 | <?php |
| 426 | } |
| 427 | |
| 428 | protected function filter_structure($show_filter_fields = false) |
| 429 | { |
| 430 | $filter_enabled = $this->get_meta('ppress_md_enable_filters') == 'true'; |
| 431 | |
| 432 | $filter_fields = apply_filters('ppress_member_directory_filter_fields', array_filter($this->get_meta('ppress_md_filter_fields'), function ($item) { |
| 433 | return ! empty($item); |
| 434 | }), $this->form_id, $this); |
| 435 | |
| 436 | if ( ! $filter_enabled || empty($filter_fields)) return; |
| 437 | |
| 438 | if ( ! $show_filter_fields) : ?> |
| 439 | <span class="ppressmd-member-directory-filters"> |
| 440 | <span class="ppressmd-member-directory-filters-a"> |
| 441 | <a href="#"> |
| 442 | <?= esc_html__('More Filters', 'wp-user-avatar') ?> |
| 443 | <span class="ppress-material-icons ppress-up">keyboard_arrow_up</span> |
| 444 | <span class="ppress-material-icons ppress-down">keyboard_arrow_down</span> |
| 445 | </a> |
| 446 | </span> |
| 447 | </span> |
| 448 | <?php endif; |
| 449 | |
| 450 | if ($show_filter_fields) : $query_params = $this->search_filter_query_params(); ?> |
| 451 | |
| 452 | <div class="ppressmd-member-directory-header-row ppressmd-member-directory-filters-bar"> |
| 453 | |
| 454 | <div class="ppressmd-search ppressmd-search-invisible"> |
| 455 | |
| 456 | <?php |
| 457 | foreach ($filter_fields as $field_key) : |
| 458 | |
| 459 | $custom_field = PROFILEPRESS_sql::get_profile_custom_field_by_key($field_key); ?> |
| 460 | |
| 461 | <div class="ppressmd-search-filter ppressmd-text-filter-type"> |
| 462 | |
| 463 | <?php |
| 464 | |
| 465 | if ($field_key == 'ppress_user_role') { |
| 466 | $this->filter_structure__select_field( |
| 467 | $query_params, |
| 468 | $field_key, |
| 469 | esc_html__('User Role', 'wp-user-avatar'), |
| 470 | apply_filters('ppress_md_user_roles_filter', ppress_wp_roles_key_value(false), $this->form_id), |
| 471 | false |
| 472 | ); |
| 473 | } |
| 474 | |
| 475 | if (is_array($custom_field)) { |
| 476 | |
| 477 | switch ($custom_field['type']) { |
| 478 | case 'select' : |
| 479 | case 'checkbox' : |
| 480 | case 'radio' : |
| 481 | case 'country' : |
| 482 | |
| 483 | if ( ! empty($custom_field['options'])) { |
| 484 | |
| 485 | $is_multiple = false; |
| 486 | |
| 487 | if ($custom_field['type'] == 'select') { |
| 488 | $is_multiple = ppress_is_select_field_multi_selectable($field_key); |
| 489 | } |
| 490 | |
| 491 | if ($custom_field['type'] == 'checkbox') $is_multiple = true; |
| 492 | |
| 493 | $options = array_map('trim', explode(',', $custom_field['options'])); |
| 494 | |
| 495 | $options = array_combine($options, $options); |
| 496 | |
| 497 | $this->filter_structure__select_field( |
| 498 | $query_params, |
| 499 | $field_key, |
| 500 | $custom_field['label_name'], |
| 501 | $options, |
| 502 | $is_multiple |
| 503 | ); |
| 504 | } |
| 505 | break; |
| 506 | |
| 507 | case 'date' : |
| 508 | |
| 509 | $dateFormat = ! empty($custom_field['options']) ? $custom_field['options'] : 'Y-m-d'; |
| 510 | |
| 511 | $config = FieldsShortcodeCallback::date_picker_config($field_key, $dateFormat); |
| 512 | |
| 513 | printf( |
| 514 | '<input type="text" name="%1$s" placeholder="%2$s" value="%4$s" class="ppressmd-form-field ppmd-date" data-config="%3$s">', |
| 515 | 'filters[' . $custom_field['field_key'] . ']', |
| 516 | $custom_field['label_name'], |
| 517 | esc_attr(json_encode($config)), |
| 518 | ppress_var(ppress_var($query_params, 'filters', []), $field_key) |
| 519 | ); |
| 520 | break; |
| 521 | } |
| 522 | } |
| 523 | ?> |
| 524 | |
| 525 | </div> |
| 526 | |
| 527 | <?php endforeach; ?> |
| 528 | |
| 529 | </div> |
| 530 | |
| 531 | </div> |
| 532 | <?php endif; |
| 533 | } |
| 534 | |
| 535 | protected function filter_structure__select_field($query_params, $field_key, $label_name, $options, $is_multiple) |
| 536 | { |
| 537 | printf( |
| 538 | '<select name="%s" data-placeholder="%s" class="ppressmd-form-field ppmd-select2"%s>', |
| 539 | $is_multiple ? 'filters[' . $field_key . '][]' : 'filters[' . $field_key . ']', |
| 540 | $label_name, |
| 541 | $is_multiple ? ' multiple' : ' data-allow-clear="true"' |
| 542 | ); |
| 543 | |
| 544 | if ( ! $is_multiple) { |
| 545 | echo '<option></option>'; |
| 546 | } |
| 547 | |
| 548 | foreach ($options as $optionKey => $option) { |
| 549 | $bucket = ppress_var(ppress_var($query_params, 'filters', []), $field_key); |
| 550 | printf( |
| 551 | '<option value="%1$s" %3$s>%2$s</option>', |
| 552 | $optionKey, |
| 553 | $option, |
| 554 | ! $is_multiple ? selected($option, $bucket, false) : (is_array($bucket) && in_array($option, $bucket) ? 'selected=selected' : '') |
| 555 | ); |
| 556 | } |
| 557 | |
| 558 | echo '</select>'; |
| 559 | } |
| 560 | |
| 561 | protected function search_form() |
| 562 | { |
| 563 | if ($this->get_meta('ppress_md_enable_search') != 'true') return; |
| 564 | |
| 565 | $search_string = apply_filters('ppressmd_member_directory_search_string', esc_html__('Search', 'wp-user-avatar')); |
| 566 | |
| 567 | $search_string_placeholder = apply_filters('ppressmd_member_directory_search_placeholder', esc_html__('Search', 'wp-user-avatar')); |
| 568 | |
| 569 | $entered_search_term = ppress_var($this->search_filter_query_params(), 'search-' . $this->form_id, ''); |
| 570 | |
| 571 | ?> |
| 572 | <div class="ppressmd-member-directory-header-row ppressmd-member-directory-search-row"> |
| 573 | <div class="ppressmd-member-directory-search-line"> |
| 574 | <label> |
| 575 | <input name="search-<?= $this->form_id ?>" type="search" class="ppressmd-search-line" placeholder="<?= $search_string_placeholder ?>" value="<?= esc_attr($entered_search_term) ?>"> |
| 576 | </label> <input type="submit" class="ppressmd-do-search ppressmd-button" value="<?= $search_string ?>"> |
| 577 | </div> |
| 578 | </div> |
| 579 | <?php |
| 580 | } |
| 581 | |
| 582 | protected function search_filter_sort_structure() |
| 583 | { |
| 584 | $is_filters_expanded = apply_filters('ppressmd_member_directory_filters_expanded', false, $this->form_id, $this); |
| 585 | |
| 586 | $query_params = $this->search_filter_query_params(); |
| 587 | |
| 588 | if (isset($query_params['filters']) && ! empty(array_filter($query_params['filters']))) { |
| 589 | $is_filters_expanded = true; |
| 590 | } |
| 591 | ?> |
| 592 | |
| 593 | <div class="ppressmd-member-directory-header ppressmd-form<?= $is_filters_expanded ? ' ppmd-filters-expand' : ''; ?>"> |
| 594 | |
| 595 | <form action="<?= ppress_get_current_url_query_string() ?>" method="get"> |
| 596 | |
| 597 | <?php $this->search_form(); ?> |
| 598 | |
| 599 | <div class="ppressmd-member-directory-header-row"> |
| 600 | <div class="ppressmd-member-directory-nav-line"> |
| 601 | |
| 602 | <?php $this->sort_method_dropdown_menu(); ?> |
| 603 | |
| 604 | <?php $this->filter_structure(); ?> |
| 605 | |
| 606 | </div> |
| 607 | </div> |
| 608 | |
| 609 | <?php $this->filter_structure(true) ?> |
| 610 | |
| 611 | <input type="hidden" name="ppmd-search" value="<?= $this->form_id ?>"> |
| 612 | |
| 613 | </form> |
| 614 | |
| 615 | </div> |
| 616 | <?php |
| 617 | } |
| 618 | |
| 619 | protected function is_result_after_search_enabled() |
| 620 | { |
| 621 | return $this->get_meta('ppress_md_enable_result_after_search') == 'true'; |
| 622 | } |
| 623 | |
| 624 | protected function get_results_text() |
| 625 | { |
| 626 | return esc_html($this->get_meta('ppress_md_results_text')); |
| 627 | } |
| 628 | |
| 629 | protected function get_single_result_text() |
| 630 | { |
| 631 | return esc_html($this->get_meta('ppress_md_single_result_text')); |
| 632 | } |
| 633 | |
| 634 | protected function get_no_result_text() |
| 635 | { |
| 636 | return esc_html($this->get_meta('ppress_md_no_result_text')); |
| 637 | } |
| 638 | |
| 639 | protected function get_default_result_number_per_page() |
| 640 | { |
| 641 | static $cache = []; |
| 642 | |
| 643 | if ( ! isset($cache[$this->form_id])) { |
| 644 | $cache[$this->form_id] = absint($this->get_meta('ppress_md_result_number_per_page')); |
| 645 | } |
| 646 | |
| 647 | return $cache[$this->form_id]; |
| 648 | } |
| 649 | |
| 650 | /** |
| 651 | * @return MemberDirectoryListing |
| 652 | */ |
| 653 | protected function directory_listing($user_id = false) |
| 654 | { |
| 655 | return (new MemberDirectoryListing($this->form_id, $user_id))->defaults($this->default_fields_settings()); |
| 656 | } |
| 657 | |
| 658 | public function form_css() |
| 659 | { |
| 660 | $form_id = $this->form_id; |
| 661 | $form_type = $this->form_type; |
| 662 | |
| 663 | $search_filter_field_text_color = esc_attr($this->get_meta('ppress_md_search_filter_field_text_color')); |
| 664 | $search_filter_field_border_color = esc_attr($this->get_meta('ppress_md_search_filter_field_border_color')); |
| 665 | |
| 666 | $pagination_link_color = esc_attr($this->get_meta('ppress_md_pagination_link_color')); |
| 667 | $pagination_active_link_color = esc_attr($this->get_meta('ppress_md_pagination_active_link_color')); |
| 668 | $pagination_active_bg_color = esc_attr($this->get_meta('ppress_md_pagination_active_background_color')); |
| 669 | |
| 670 | return <<<CSS |
| 671 | #pp-$form_type-$form_id.pp-member-directory .ppressmd-member-directory-header .ppressmd-member-directory-header-row .ppressmd-member-directory-search-line label .ppressmd-search-line, |
| 672 | #pp-$form_type-$form_id.pp-member-directory .ppressmd-member-directory-header .ppressmd-member-directory-header-row .ppressmd-search .ppressmd-search-filter.ppressmd-text-filter-type input:not(.select2-search__field), |
| 673 | #pp-$form_type-$form_id.pp-member-directory .ppressmd-member-directory-header .select2.select2-container .select2-selection { |
| 674 | border: 1px solid $search_filter_field_border_color !important; |
| 675 | } |
| 676 | |
| 677 | #pp-$form_type-$form_id.pp-member-directory .ppressmd-member-directory-header .ppressmd-member-directory-header-row .ppressmd-search .ppressmd-search-filter.ppressmd-text-filter-type input, |
| 678 | #pp-$form_type-$form_id.pp-member-directory .ppressmd-member-directory-header .ppressmd-member-directory-header-row .ppressmd-member-directory-search-line label .ppressmd-search-line, |
| 679 | #pp-$form_type-$form_id.pp-member-directory .ppressmd-member-directory-header .ppressmd-member-directory-header-row .ppressmd-member-directory-nav-line .ppress-material-icons, |
| 680 | #pp-$form_type-$form_id.pp-member-directory .ppressmd-member-directory-header .select2.select2-container .select2-selection__rendered { |
| 681 | color: $search_filter_field_text_color !important; |
| 682 | } |
| 683 | |
| 684 | #pp-$form_type-$form_id.pp-member-directory .ppmd-pagination-wrap .page-numbers { |
| 685 | color: $pagination_link_color !important; |
| 686 | } |
| 687 | |
| 688 | #pp-$form_type-$form_id.pp-member-directory .ppmd-pagination-wrap .page-numbers.current { |
| 689 | background: $pagination_active_bg_color !important; |
| 690 | color: $pagination_active_link_color !important; |
| 691 | } |
| 692 | CSS; |
| 693 | |
| 694 | } |
| 695 | } |
| 696 |