PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.71
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.71
1.2.72 1.2.71 1.2.70 1.2.69 1.2.68 1.2.67 1.2.66 1.2.65 1.2.64 1.2.63 trunk 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.20 1.0.21 1.0.22 1.0.23 All 172 releases
userswp / includes / helpers / pages.php

pages.php in UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP 1.2.71, at includes/helpers/pages.php

615 lines 19.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Checks whether the current page is of given page type or not.
4 *
5 * @since 1.0.0
6 * @package userswp
7 * @param string|bool $type Page type.
8 * @return bool
9 */
10 function is_uwp_page($type = false) {
11 $page = new UsersWP_Pages();
12 return $page->is_page($type);
13 }
14
15 /**
16 * Checks whether the current page is register page or not.
17 *
18 * @since 1.0.0
19 * @package userswp
20 * @return bool
21 */
22 function is_uwp_register_page() {
23 $page = new UsersWP_Pages();
24 return $page->is_register_page();
25 }
26
27 /**
28 * Checks whether the current page is login page or not.
29 *
30 * @since 1.0.0
31 * @package userswp
32 * @return bool
33 */
34 function is_uwp_login_page() {
35 $page = new UsersWP_Pages();
36 return $page->is_login_page();
37 }
38
39 /**
40 * Checks whether the current page is forgot password page or not.
41 *
42 * @since 1.0.0
43 * @package userswp
44 * @return bool
45 */
46 function is_uwp_forgot_page() {
47 $page = new UsersWP_Pages();
48 return $page->is_forgot_page();
49 }
50
51 /**
52 * Checks whether the current page is change password page or not.
53 *
54 * @since 1.0.0
55 * @package userswp
56 * @return bool
57 */
58 function is_uwp_change_page() {
59 $page = new UsersWP_Pages();
60 return $page->is_change_page();
61 }
62
63 /**
64 * Checks whether the current page is reset password page or not.
65 *
66 * @since 1.0.0
67 * @package userswp
68 * @return bool
69 */
70 function is_uwp_reset_page() {
71 $page = new UsersWP_Pages();
72 return $page->is_reset_page();
73 }
74
75 /**
76 * Checks whether the current page is account page or not.
77 *
78 * @since 1.0.0
79 * @package userswp
80 * @return bool
81 */
82 function is_uwp_account_page() {
83 $page = new UsersWP_Pages();
84 return $page->is_account_page();
85 }
86
87 /**
88 * Checks whether the current page is profile page or not.
89 *
90 * @since 1.0.0
91 * @package userswp
92 * @return bool
93 */
94 function is_uwp_profile_page() {
95 $page = new UsersWP_Pages();
96 return $page->is_profile_page();
97 }
98
99 /**
100 * Checks whether the current page is users page or not.
101 *
102 * @since 1.0.0
103 * @package userswp
104 * @return bool
105 */
106 function is_uwp_users_page() {
107 $page = new UsersWP_Pages();
108 return $page->is_users_page();
109 }
110
111 /**
112 * Checks whether the current page is users list item page or not.
113 *
114 * @since 1.0.0
115 * @package userswp
116 * @return bool
117 */
118 function is_uwp_users_item_page() {
119 $page = new UsersWP_Pages();
120 return $page->is_user_item_page();
121 }
122
123 /**
124 * Checks whether the current page is logged in user profile page or not.
125 *
126 * @since 1.0.0
127 * @package userswp
128 * @return bool
129 */
130 function is_uwp_current_user_profile_page() {
131 $page = new UsersWP_Pages();
132 return $page->is_current_user_profile_page();
133 }
134
135 /**
136 * Returns all available pages as array to use in select dropdown.
137 *
138 * @since 1.0.0
139 * @package userswp
140 * @return array Page array.
141 */
142 function uwp_get_pages() {
143 $page = new UsersWP_Pages();
144 return $page->get_pages();
145 }
146
147 /**
148 * Gets the page slug using the given page type.
149 *
150 * @since 1.0.0
151 * @package userswp
152 * @param string $page_type Page type.
153 * @return string Page slug.
154 */
155 function uwp_get_page_slug($page_type = 'register_page') {
156 $page = new UsersWP_Pages();
157 return $page->get_page_slug($page_type);
158 }
159
160 /**
161 * Creates UsersWP page if not exists.
162 *
163 * @since 1.0.0
164 * @package userswp
165 * @param string $slug Page slug.
166 * @param string $option Page setting key.
167 * @param string $page_title The post title. Default empty.
168 * @param mixed $page_content The post content. Default empty.
169 * @param int $post_parent Set this for the post it belongs to, if any. Default 0.
170 * @param string $status The post status. Default 'draft'.
171 */
172 function uwp_create_page($slug, $option, $page_title = '', $page_content = '', $post_parent = 0, $status = 'publish') {
173 $page = new UsersWP_Pages();
174 $page->create_page($slug, $option, $page_title, $page_content, $post_parent, $status);
175 }
176
177 /**
178 * Generates default UsersWP pages. Usually called during plugin activation.
179 *
180 * @since 1.0.0
181 * @package userswp
182 * @return void
183 */
184 function uwp_generate_default_pages() {
185 $page = new UsersWP_Pages();
186 $page->generate_default_pages();
187 }
188
189 function uwp_get_page_id($type, $link = false) {
190 $page = new UsersWP_Pages();
191 return $page->get_page_id($type, $link);
192 }
193
194 function uwp_get_user_badge($args){
195 global $wpdb;
196
197 if ( isset($args) && empty( $args['user_id'] ) ) {
198 return;
199 }
200
201 $user = get_userdata($args['user_id']);
202 if(!$user){
203 return;
204 }
205
206 $defaults = array(
207 'user_id' => 0,
208 'key' => '',
209 'condition' => '',
210 'search' => 'is_equal',
211 'badge' => '',
212 'link' => '',
213 'new_window' => '',
214 'bg_color' => '#0073aa',
215 'txt_color' => '#ffffff',
216 'size' => '',
217 'alignment' => '',
218 'css_class' => '',
219 'onclick' => '',
220 'icon_class'=> '',
221 'extra_attributes'=> '',
222 'tag' => '',
223 'popover_title'=> '',
224 'popover_text'=> '',
225 'tooltip_text' => '',
226 'hover_content' => '',
227 'hover_icon' => '',
228 'type'=> '', // AUI only
229 'color'=> '', // AUI only
230 'shadow'=> '', // AUI only
231 );
232
233 $args = shortcode_atts( $defaults, $args, 'uwp_user_badge' );
234
235 $output = '';
236 $table_name = uwp_get_table_prefix() . 'uwp_form_fields';
237 $match_field = $args['key'];
238 $badge = $args['badge'];
239 $field = array();
240 $user_id = $user->ID;
241
242 // Check if there is a specific filter for field.
243 if ( has_filter( 'uwp_output_badge_field_key_' . $match_field ) ) {
244 $output = apply_filters( 'uwp_output_badge_field_key_' . $match_field, $output, $user, $args );
245 }
246
247 if ( $match_field ) {
248 $form_id = uwp_get_register_form_id( $user->ID );
249 $fields = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $table_name . " WHERE form_type = 'account' AND htmlvar_name = %s AND form_id = %d", $match_field, $form_id));
250
251 if(!$fields){
252 return $output;
253 }
254
255 $field = isset($fields[0]) ? $fields[0] : '';
256
257 if ( ! empty( $field ) ) {
258 // Check if there is a specific filter for key type.
259 if ( has_filter( 'uwp_output_badge_key_' . $field->field_type_key ) ) {
260 $output = apply_filters( 'uwp_output_badge_key_' . $field->field_type_key, $output, $user, $args, $field );
261 }
262
263 // Check if there is a specific filter for condition.
264 if ( has_filter( 'uwp_output_badge_condition_' . $args['condition'] ) ) {
265 $output = apply_filters( 'uwp_output_badge_condition_' . $args['condition'], $output, $user, $args, $field );
266 }
267 } else {
268 return $output;
269 }
270 }
271
272 // If not then we run the standard output.
273 if ( empty( $output ) ) {
274 $search = $args['search'];
275 $match_found = $match_field === '' ? true : false;
276 $is_date = ( isset( $field->field_type ) && $field->field_type == 'datepicker' ) ? true : false;
277 $is_date = apply_filters( 'uwp_user_badge_is_date', $is_date, $match_field, $field, $args );
278
279 $excluded_fields = uwp_get_excluded_fields();
280 if(isset($field->htmlvar_name) && in_array($field->htmlvar_name, $excluded_fields)){
281 $match_value = '';
282 } else {
283 $match_value = uwp_get_usermeta($user->ID, $field->htmlvar_name, "");
284 }
285
286 if ( ! $match_found ) {
287 if ( $field->field_type == 'datepicker' && empty( $args['condition'] ) || $args['condition'] == 'is_greater_than' || $args['condition'] == 'is_less_than' ) {
288 if( ( empty($args['condition']) || $args['condition'] == 'is_less_than' ) && strpos( $search, '-' ) === false ) {
289 $search = str_replace('+','',$search);
290 $search = '-' . $search;
291 } elseif ( $args['condition'] == 'is_greater_than' && strpos( $search, '+' ) === false ) {
292 $search = str_replace('-','',$search);
293 $search = '+' . $search;
294 }
295
296 $the_time = strtotime(date( 'Y-m-d', $match_value ));
297 $until_time = strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) . ' ' . $search . ' days' );
298 $now_time = strtotime( date_i18n( 'Y-m-d', current_time( 'timestamp' ) ) );
299
300
301 if ( ( empty( $args['condition'] ) || $args['condition'] == 'is_less_than' ) && $the_time <= $now_time && $the_time >= $until_time ) {
302 $match_found = true;
303 } elseif ( $args['condition'] == 'is_greater_than' && $the_time >= $now_time && $the_time <= $until_time ) {
304 $match_found = true;
305 }
306 } else {
307 switch ( $args['condition'] ) {
308 case 'is_equal':
309 $match_found = (bool) ( $search != '' && $match_value == $search );
310 break;
311 case 'is_not_equal':
312 $match_found = (bool) ( $search != '' && $match_value != $search );
313 break;
314 case 'is_greater_than':
315 $match_found = (bool) ( $search != '' && is_float( $search ) && is_float( $match_value ) && $match_value > $search );
316 break;
317 case 'is_less_than':
318 $match_found = (bool) ( $search != '' && is_float( $search ) && is_float( $match_value ) && $match_value < $search );
319 break;
320 case 'is_empty':
321 $match_found = (bool) ( $match_value === '' || $match_value === false || $match_value === '0' || is_null( $match_value ) );
322 break;
323 case 'is_not_empty':
324 $match_found = (bool) ( $match_value !== '' && $match_value !== false && $match_value !== '0' && ! is_null( $match_value ) );
325 break;
326 case 'is_contains':
327 $match_found = (bool) ( $search != '' && stripos( $match_value, $search ) !== false );
328 break;
329 case 'is_not_contains':
330 $match_found = (bool) ( $search != '' && stripos( $match_value, $search ) === false );
331 break;
332 }
333 }
334 }
335
336 $match_found = apply_filters( 'uwp_user_badge_check_match_found', $match_found, $args, $user );
337
338 if ( $match_found ) {
339 if ( $is_date && ! empty( $match_value ) && strpos( $match_value, '0000-00-00' ) === false ) {
340 $args['datetime'] = mysql2date( 'c', $match_value, false );
341 }
342
343 // Option value
344 if ( ! empty( $field->option_values ) ) {
345 $option_values = uwp_string_values_to_options( stripslashes_deep( $field->option_values ), true );
346
347 if ( ! empty( $option_values ) ) {
348 if ( ! empty( $field->option_values ) && $field->option_values == 'multiselect' ) {
349 $values = explode( ',', trim( $match_value, ', ' ) );
350
351 if ( is_array( $values ) ) {
352 $values = array_map( 'trim', $values );
353 }
354
355 $_match_value = array();
356 foreach ( $option_values as $option_value ) {
357 if ( isset( $option_value['value'] ) && in_array( $option_value['value'], $values ) ) {
358 $_match_value[] = $option_value['label'];
359 }
360 }
361
362 $match_value = ! empty( $_match_value ) ? implode( ', ', $_match_value ) : '';
363 } else {
364 foreach ( $option_values as $option_value ) {
365 if ( isset( $option_value['value'] ) && $option_value['value'] == $match_value ) {
366 $match_value = $option_value['label'];
367 }
368 }
369 }
370 }
371 }
372
373 $match_value = apply_filters( 'uwp_post_badge_match_value', $match_value, $match_field, $args, $user, $field );
374
375 // File
376 if ( ! empty( $badge ) && ! empty( $match_value ) && ! empty( $field->field_type ) && $field->field_type == 'file' ) {
377 $badge = $match_value;
378 }
379
380 // badge text
381 if ( empty( $badge ) && empty($args['icon_class']) ) {
382 $badge = isset($field->site_title) ? $field->site_title : '';
383 }
384 // Decode entities in the admin-authored template text now, before any
385 // untrusted user values are substituted in below. Decoding after
386 // substitution would undo the escaping applied to those values.
387 if ( ! empty( $badge ) ) {
388 $badge = wp_specialchars_decode( $badge, ENT_QUOTES );
389 }
390 if( !empty( $badge ) && $badge = str_replace("%%input%%", esc_html( (string) $match_value ), $badge) ){
391 // will be replace in condition check
392 }
393 if( !empty( $badge ) && $user_id && $badge = str_replace("%%profile_url%%", esc_url( uwp_build_profile_tab_url($user_id) ),$badge) ){
394 // will be replace in condition check
395 }
396
397 // link url, replace vars
398 if ( ! empty( $args['link'] ) && $args['link'] = str_replace( "%%input%%", $match_value, $args['link'] ) ) {
399 // will be replace in condition check
400 if ( ! empty( $field->field_type ) && $field->field_type == 'url' ) {
401 $args['link'] = esc_url( $args['link'] );
402 } else {
403 $args['link'] = esc_attr( $args['link'] );
404 }
405 }
406
407 if( !empty( $args['link'] ) && $user_id && $args['link'] = str_replace("%%profile_url%%", uwp_build_profile_tab_url($user_id),$args['link']) ){
408 // will be replace in condition check
409 }
410
411 // replace other post variables
412 if(!empty($badge)){
413 $badge = uwp_replace_variables($badge, $user_id);
414 }
415 if(!empty($args['popover_title'])){
416 $args['popover_title'] = uwp_replace_variables($args['popover_title'], $user_id);
417 }
418 if(!empty($args['popover_text'])){
419 $args['popover_text'] = uwp_replace_variables($args['popover_text'], $user_id);
420 }
421 if(!empty($args['tooltip_text'])){
422 $args['tooltip_text'] = uwp_replace_variables($args['tooltip_text'], $user_id);
423 }
424 if(!empty($args['hover_content'])){
425 $args['hover_content'] = uwp_replace_variables($args['hover_content'], $user_id);
426 }
427
428 $rel = '';
429 if(!empty($args['link'])){
430 $rel = strpos($args['link'], get_site_url()) !== false ? '' : 'rel="nofollow"';
431 }
432
433 $new_window = '';
434 if ( ! empty( $args['new_window'] ) ) {
435 $new_window = ' target="_blank" ';
436 }
437
438 $badge = ! empty( $badge ) ? __( $badge, 'userswp' ) : '';
439
440 // phone & email link
441 if ( ! empty( $field ) && ! empty( $field->field_type ) && ! empty( $args['link'] ) && strpos( $args['link'], 'http' ) !== 0 ) {
442 if ( $field->field_type == 'phone' ) {
443 $rel = 'rel="nofollow"';
444 if ( strpos( $args['link'], 'tel:' ) !== 0 ) {
445 $args['link'] = 'tel:' . preg_replace( '/[^0-9+]/', '', $args['link'] );
446 }
447 } elseif ( $field->field_type == 'email' ) {
448 $rel = 'rel="nofollow"';
449 if ( strpos( $args['link'], 'mailto:' ) !== 0 ) {
450 $args['link'] = 'mailto:' . $args['link'];
451 }
452 }
453 }
454
455 $badge = apply_filters( 'uwp_user_badge_output_badge', $badge, $match_value, $match_field, $args, $user, $field );
456
457 $btn_class = 'border-0 align-middle uwp-badge';
458 // color
459 $color_custom = true;
460 if( !empty( $args['color'] ) ) {
461 $btn_class .= ' badge-' . sanitize_html_class($args['color']);
462 $color_custom = false;
463 }else{
464 $btn_class .= ' badge-primary'; // custom colors will override this anyway.
465 }
466
467 // shadow
468 if( !empty( $args['shadow'] ) ) {
469 if($args['shadow']=='small'){ $btn_class .= ' shadow-sm'; }
470 elseif($args['shadow']=='medium'){ $btn_class .= ' shadow'; }
471 elseif($args['shadow']=='large'){ $btn_class .= ' shadow-lg'; }
472 }
473
474 // type
475 if( !empty( $args['type'] ) && $args['type']=='pill' ){
476 $btn_class .= ' badge badge-pill';
477 }else{
478 $btn_class .= ' badge';
479 }
480
481 if ( ! empty( $args['css_class'] ) ) {
482 $btn_class .= ' ' .esc_attr($args['css_class']) ;
483 }
484 $btn_args = array(
485 'class' => $btn_class,
486 'content' => $badge,
487 'style' => $color_custom ? 'background-color:' . sanitize_hex_color( $args['bg_color'] ) . ';color:' . sanitize_hex_color( $args['txt_color'] ) . ';' : '',
488 'data-badge' => esc_attr($match_field),
489 'data-badge-condition' => esc_attr($args['condition']),
490 );
491
492 // onclick
493 if(!empty($args['onclick'])){
494 $btn_args['onclick'] = esc_attr($args['onclick']);
495 }
496
497 // popover / tooltip
498 $pop_link = false;
499 if(!empty($args['popover_title']) || !empty($args['popover_text'])){
500 $btn_args['type'] = "button";
501 $btn_args['data-toggle'] = "popover-html";
502 $btn_args['data-placement'] = "top";
503 $pop_link = true;
504 if(!empty($args['popover_title'])){
505 $btn_args['title'] = !empty($args['link']) && $args['link']!='#' ? "<a href='".esc_url($args['link'])."' $new_window $rel>".$args['popover_title']."</a>" : $args['popover_title'];
506 }
507 if(!empty($args['popover_text'])){
508 $btn_args['data-content'] = !empty($args['link']) && $args['link']!='#' ? "<a href='".esc_url($args['link'])."' $new_window $rel>".$args['popover_text']."</a>" : $args['popover_text'];
509 }
510 }elseif(!empty($args['tooltip_text'])){
511 $btn_args['data-toggle'] = "tooltip";
512 $btn_args['data-placement'] = "top";
513 $btn_args['title'] = esc_attr($args['tooltip_text']);
514 }
515
516 // hover content
517 if(!empty($args['hover_content'])){
518 $btn_args['hover_content'] = $args['hover_content'];
519 }
520 if(!empty($args['hover_icon'])){
521 $btn_args['hover_icon'] = $args['hover_icon'];
522 }
523
524 // style
525 $btn_args['style'] = '';
526 if($color_custom && !empty($args['bg_color'])){
527 $btn_args['style'] .= 'background-color:' . sanitize_hex_color( $args['bg_color'] ) . ';border-color:' . sanitize_hex_color( $args['bg_color'] ).';';
528 }
529 if($color_custom && !empty($args['txt_color'])){
530 $btn_args['style'] .= 'color:' . sanitize_hex_color( $args['txt_color'] ) . ';';
531 }
532
533 if(!empty($args['link']) && $args['link']!='#' && !$pop_link){
534 $btn_args['href'] = $args['link'];
535 }
536
537 if(!empty($args['link']) && $new_window){
538 $btn_args['new_window'] = true;
539 }
540
541 if(!empty($args['icon_class'])) { $btn_args['icon'] = $args['icon_class'];}
542
543 $output = '<span class="bsui uwp-badge-meta">';
544 if(!empty($args['size'])){$output .= '<span class="'.esc_attr($args['size']).'">';}
545 $output .= aui()->badge( $btn_args );
546 if(!empty($args['size'])){$output .= '</span>';}
547 $output .= '</span>';
548 }
549 }
550
551 return $output;
552 }
553
554 function uwp_aui_colors($include_branding = false){
555 $theme_colors = array(
556 "primary" => __('Primary', 'userswp'),
557 "secondary" => __('Secondary', 'userswp'),
558 "success" => __('Success', 'userswp'),
559 "danger" => __('Danger', 'userswp'),
560 "warning" => __('Warning', 'userswp'),
561 "info" => __('Info', 'userswp'),
562 "light" => __('Light', 'userswp'),
563 "dark" => __('Dark', 'userswp'),
564 "white" => __('White', 'userswp'),
565 "purple" => __('Purple', 'userswp'),
566 "salmon" => __('Salmon', 'userswp'),
567 "cyan" => __('Cyan', 'userswp'),
568 "gray" => __('Gray', 'userswp'),
569 "indigo" => __('Indigo', 'userswp'),
570 "orange" => __('Orange', 'userswp'),
571 );
572
573 if($include_branding){
574 $theme_colors = $theme_colors + uwp_aui_branding_colors();
575 }
576
577 return $theme_colors;
578 }
579
580 function uwp_aui_branding_colors(){
581 return array(
582 "facebook" => __('Facebook', 'userswp'),
583 "twitter" => __('Twitter', 'userswp'),
584 "instagram" => __('Instagram', 'userswp'),
585 "linkedin" => __('Linkedin', 'userswp'),
586 "flickr" => __('Flickr', 'userswp'),
587 "github" => __('GitHub', 'userswp'),
588 "youtube" => __('YouTube', 'userswp'),
589 "wordpress" => __('WordPress', 'userswp'),
590 "google" => __('Google', 'userswp'),
591 "yahoo" => __('Yahoo', 'userswp'),
592 "vkontakte" => __('Vkontakte', 'userswp'),
593 );
594 }
595
596 function uwp_replace_variables($text, $user_id = ''){
597 // only run if we have a user ID and the start of a var
598 if(!empty($user_id) && strpos( $text, '%%' ) !== false){
599 $excluded_fields = uwp_get_excluded_fields();
600 $user_data = uwp_get_usermeta_row($user_id);
601 if(isset($user_data)){
602 foreach($user_data as $key => $val) {
603 if ( ! in_array( $key, $excluded_fields ) ) {
604 $val = apply_filters( 'uwp_replace_variables_' . $key, $val, $text );
605 if ( is_scalar( $val ) ) {
606 $val = esc_html( (string) $val );
607 }
608 $text = str_replace( '%%' . $key . '%%', $val, $text );
609 }
610 }
611 }
612 }
613
614 return $text;
615 }