PluginProbe
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP / 1.2.65
UsersWP – Front-end login form, User Registration, User Profile & Members Directory plugin for WP v1.2.65
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.65, at includes/helpers/pages.php

606 lines 18.7 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 if( !empty( $badge ) && $badge = str_replace("%%input%%", $match_value,$badge) ){
385 // will be replace in condition check
386 }
387 if( !empty( $badge ) && $user_id && $badge = str_replace("%%profile_url%%", uwp_build_profile_tab_url($user_id),$badge) ){
388 // will be replace in condition check
389 }
390
391 // link url, replace vars
392 if ( ! empty( $args['link'] ) && $args['link'] = str_replace( "%%input%%", $match_value, $args['link'] ) ) {
393 // will be replace in condition check
394 if ( ! empty( $field->field_type ) && $field->field_type == 'url' ) {
395 $args['link'] = esc_url( $args['link'] );
396 } else {
397 $args['link'] = esc_attr( $args['link'] );
398 }
399 }
400
401 if( !empty( $args['link'] ) && $user_id && $args['link'] = str_replace("%%profile_url%%", uwp_build_profile_tab_url($user_id),$args['link']) ){
402 // will be replace in condition check
403 }
404
405 // replace other post variables
406 if(!empty($badge)){
407 $badge = uwp_replace_variables($badge, $user_id);
408 }
409 if(!empty($args['popover_title'])){
410 $args['popover_title'] = uwp_replace_variables($args['popover_title'], $user_id);
411 }
412 if(!empty($args['popover_text'])){
413 $args['popover_text'] = uwp_replace_variables($args['popover_text'], $user_id);
414 }
415 if(!empty($args['tooltip_text'])){
416 $args['tooltip_text'] = uwp_replace_variables($args['tooltip_text'], $user_id);
417 }
418 if(!empty($args['hover_content'])){
419 $args['hover_content'] = uwp_replace_variables($args['hover_content'], $user_id);
420 }
421
422 $rel = '';
423 if(!empty($args['link'])){
424 $rel = strpos($args['link'], get_site_url()) !== false ? '' : 'rel="nofollow"';
425 }
426
427 $new_window = '';
428 if ( ! empty( $args['new_window'] ) ) {
429 $new_window = ' target="_blank" ';
430 }
431
432 $badge = ! empty( $badge ) ? __( wp_specialchars_decode( $badge, ENT_QUOTES ), 'userswp' ) : '';
433
434 // phone & email link
435 if ( ! empty( $field ) && ! empty( $field->field_type ) && ! empty( $args['link'] ) && strpos( $args['link'], 'http' ) !== 0 ) {
436 if ( $field->field_type == 'phone' ) {
437 $rel = 'rel="nofollow"';
438 if ( strpos( $args['link'], 'tel:' ) !== 0 ) {
439 $args['link'] = 'tel:' . preg_replace( '/[^0-9+]/', '', $args['link'] );
440 }
441 } elseif ( $field->field_type == 'email' ) {
442 $rel = 'rel="nofollow"';
443 if ( strpos( $args['link'], 'mailto:' ) !== 0 ) {
444 $args['link'] = 'mailto:' . $args['link'];
445 }
446 }
447 }
448
449 $badge = apply_filters( 'uwp_user_badge_output_badge', $badge, $match_value, $match_field, $args, $user, $field );
450
451 $btn_class = 'border-0 align-middle uwp-badge';
452 // color
453 $color_custom = true;
454 if( !empty( $args['color'] ) ) {
455 $btn_class .= ' badge-' . sanitize_html_class($args['color']);
456 $color_custom = false;
457 }else{
458 $btn_class .= ' badge-primary'; // custom colors will override this anyway.
459 }
460
461 // shadow
462 if( !empty( $args['shadow'] ) ) {
463 if($args['shadow']=='small'){ $btn_class .= ' shadow-sm'; }
464 elseif($args['shadow']=='medium'){ $btn_class .= ' shadow'; }
465 elseif($args['shadow']=='large'){ $btn_class .= ' shadow-lg'; }
466 }
467
468 // type
469 if( !empty( $args['type'] ) && $args['type']=='pill' ){
470 $btn_class .= ' badge badge-pill';
471 }else{
472 $btn_class .= ' badge';
473 }
474
475 if ( ! empty( $args['css_class'] ) ) {
476 $btn_class .= ' ' .esc_attr($args['css_class']) ;
477 }
478 $btn_args = array(
479 'class' => $btn_class,
480 'content' => $badge,
481 'style' => $color_custom ? 'background-color:' . sanitize_hex_color( $args['bg_color'] ) . ';color:' . sanitize_hex_color( $args['txt_color'] ) . ';' : '',
482 'data-badge' => esc_attr($match_field),
483 'data-badge-condition' => esc_attr($args['condition']),
484 );
485
486 // onclick
487 if(!empty($args['onclick'])){
488 $btn_args['onclick'] = esc_attr($args['onclick']);
489 }
490
491 // popover / tooltip
492 $pop_link = false;
493 if(!empty($args['popover_title']) || !empty($args['popover_text'])){
494 $btn_args['type'] = "button";
495 $btn_args['data-toggle'] = "popover-html";
496 $btn_args['data-placement'] = "top";
497 $pop_link = true;
498 if(!empty($args['popover_title'])){
499 $btn_args['title'] = !empty($args['link']) && $args['link']!='#' ? "<a href='".esc_url($args['link'])."' $new_window $rel>".$args['popover_title']."</a>" : $args['popover_title'];
500 }
501 if(!empty($args['popover_text'])){
502 $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'];
503 }
504 }elseif(!empty($args['tooltip_text'])){
505 $btn_args['data-toggle'] = "tooltip";
506 $btn_args['data-placement'] = "top";
507 $btn_args['title'] = esc_attr($args['tooltip_text']);
508 }
509
510 // hover content
511 if(!empty($args['hover_content'])){
512 $btn_args['hover_content'] = $args['hover_content'];
513 }
514 if(!empty($args['hover_icon'])){
515 $btn_args['hover_icon'] = $args['hover_icon'];
516 }
517
518 // style
519 $btn_args['style'] = '';
520 if($color_custom && !empty($args['bg_color'])){
521 $btn_args['style'] .= 'background-color:' . sanitize_hex_color( $args['bg_color'] ) . ';border-color:' . sanitize_hex_color( $args['bg_color'] ).';';
522 }
523 if($color_custom && !empty($args['txt_color'])){
524 $btn_args['style'] .= 'color:' . sanitize_hex_color( $args['txt_color'] ) . ';';
525 }
526
527 if(!empty($args['link']) && $args['link']!='#' && !$pop_link){
528 $btn_args['href'] = $args['link'];
529 }
530
531 if(!empty($args['link']) && $new_window){
532 $btn_args['new_window'] = true;
533 }
534
535 if(!empty($args['icon_class'])) { $btn_args['icon'] = $args['icon_class'];}
536
537 $output = '<span class="bsui uwp-badge-meta">';
538 if(!empty($args['size'])){$output .= '<span class="'.esc_attr($args['size']).'">';}
539 $output .= aui()->badge( $btn_args );
540 if(!empty($args['size'])){$output .= '</span>';}
541 $output .= '</span>';
542 }
543 }
544
545 return $output;
546 }
547
548 function uwp_aui_colors($include_branding = false){
549 $theme_colors = array(
550 "primary" => __('Primary', 'userswp'),
551 "secondary" => __('Secondary', 'userswp'),
552 "success" => __('Success', 'userswp'),
553 "danger" => __('Danger', 'userswp'),
554 "warning" => __('Warning', 'userswp'),
555 "info" => __('Info', 'userswp'),
556 "light" => __('Light', 'userswp'),
557 "dark" => __('Dark', 'userswp'),
558 "white" => __('White', 'userswp'),
559 "purple" => __('Purple', 'userswp'),
560 "salmon" => __('Salmon', 'userswp'),
561 "cyan" => __('Cyan', 'userswp'),
562 "gray" => __('Gray', 'userswp'),
563 "indigo" => __('Indigo', 'userswp'),
564 "orange" => __('Orange', 'userswp'),
565 );
566
567 if($include_branding){
568 $theme_colors = $theme_colors + uwp_aui_branding_colors();
569 }
570
571 return $theme_colors;
572 }
573
574 function uwp_aui_branding_colors(){
575 return array(
576 "facebook" => __('Facebook', 'userswp'),
577 "twitter" => __('Twitter', 'userswp'),
578 "instagram" => __('Instagram', 'userswp'),
579 "linkedin" => __('Linkedin', 'userswp'),
580 "flickr" => __('Flickr', 'userswp'),
581 "github" => __('GitHub', 'userswp'),
582 "youtube" => __('YouTube', 'userswp'),
583 "wordpress" => __('WordPress', 'userswp'),
584 "google" => __('Google', 'userswp'),
585 "yahoo" => __('Yahoo', 'userswp'),
586 "vkontakte" => __('Vkontakte', 'userswp'),
587 );
588 }
589
590 function uwp_replace_variables($text, $user_id = ''){
591 // only run if we have a user ID and the start of a var
592 if(!empty($user_id) && strpos( $text, '%%' ) !== false){
593 $excluded_fields = uwp_get_excluded_fields();
594 $user_data = uwp_get_usermeta_row($user_id);
595 if(isset($user_data)){
596 foreach($user_data as $key => $val) {
597 if ( ! in_array( $key, $excluded_fields ) ) {
598 $val = apply_filters( 'uwp_replace_variables_' . $key, $val, $text );
599 $text = str_replace( '%%' . $key . '%%', $val, $text );
600 }
601 }
602 }
603 }
604
605 return $text;
606 }