Files
ultimatemember/core/um-profile.php
T

201 lines
3.9 KiB
PHP
Raw Normal View History

2014-12-29 15:51:55 +02:00
<?php
class UM_Profile {
2016-04-23 21:35:39 +08:00
public $arr_user_slugs = array();
public $arr_user_roles = array();
2014-12-29 15:51:55 +02:00
function __construct() {
2016-03-15 16:29:43 -07:00
2015-01-24 23:39:43 +02:00
add_action('template_redirect', array(&$this, 'active_tab'), 10002);
2015-02-01 01:30:04 +02:00
add_action('template_redirect', array(&$this, 'active_subnav'), 10002);
2016-03-15 16:29:43 -07:00
2015-01-24 23:39:43 +02:00
}
2016-03-15 16:29:43 -07:00
2015-01-24 23:39:43 +02:00
/***
2015-02-01 01:30:04 +02:00
*** @all tab data
2015-01-24 23:39:43 +02:00
***/
function tabs(){
2016-03-15 16:29:43 -07:00
$tabs = apply_filters('um_profile_tabs', $tabs = array() );
// disable private tabs
if( !is_admin() ) {
foreach( $tabs as $id => $tab ) {
if( !$this->can_view_tab( $id ) ) {
unset( $tabs[$id] );
}
}
}
return $tabs;
2015-01-24 23:39:43 +02:00
}
2016-03-15 16:29:43 -07:00
2015-01-24 23:39:43 +02:00
/***
2015-02-01 01:30:04 +02:00
*** @tabs that are active
***/
function tabs_active(){
$tabs = $this->tabs();
foreach( $tabs as $id => $info ) {
2015-11-05 19:51:31 +08:00
if ( !um_get_option('profile_tab_'.$id) && !isset( $info['_builtin'] ) && !isset( $info['custom'] ) )
2015-02-01 01:30:04 +02:00
unset( $tabs[$id] );
}
return $tabs;
}
2016-03-15 16:29:43 -07:00
2015-02-01 01:30:04 +02:00
/***
*** @primary tabs only
***/
function tabs_primary(){
$tabs = $this->tabs();
foreach( $tabs as $id => $info ){
2015-04-25 21:41:47 +02:00
if ( isset( $info['name'] ) ) {
$primary[$id] = $info['name'];
}
2015-02-01 01:30:04 +02:00
}
return $primary;
}
2016-03-15 16:29:43 -07:00
2015-05-02 02:49:05 +03:00
/***
*** @Activated tabs in backend
***/
function tabs_enabled(){
$tabs = $this->tabs();
foreach( $tabs as $id => $info ){
if ( isset( $info['name'] ) ) {
if ( um_get_option('profile_tab_'.$id) || isset( $info['_builtin'] ) ) {
$primary[$id] = $info['name'];
}
}
}
return ( isset( $primary ) ) ? $primary : '';
}
2016-03-15 16:29:43 -07:00
/***
*** @Privacy options
***/
function tabs_privacy() {
$privacy = array(
0 => 'Anyone',
1 => 'Guests only',
2 => 'Members only',
3 => 'Only the owner',
4 => 'Specific roles'
);
return $privacy;
}
/***
*** @Check if the user can view the current tab
***/
function can_view_tab( $tab ) {
global $ultimatemember;
$privacy = intval( um_get_option( 'profile_tab_' . $tab . '_privacy' ) );
$can_view = false;
switch( $privacy ) {
case 1:
$can_view = is_user_logged_in() ? false : true;
break;
case 2:
$can_view = is_user_logged_in() ? true : false;
break;
case 3:
$can_view = get_current_user_id() == um_user( 'ID' ) ? true : false;
break;
case 4:
$can_view = false;
if( is_user_logged_in() ) {
$roles = um_get_option( 'profile_tab_' . $tab . '_roles' );
if( is_array( $roles )
&& in_array( $ultimatemember->user->get_role(), $roles ) ) {
$can_view = true;
}
}
break;
default:
$can_view = true;
break;
}
return $can_view;
}
2015-02-01 01:30:04 +02:00
/***
*** @Get active_tab
2015-01-24 23:39:43 +02:00
***/
function active_tab() {
2015-05-02 02:49:05 +03:00
2015-02-01 01:30:04 +02:00
$this->active_tab = um_get_option('profile_menu_default_tab');
2015-05-02 02:49:05 +03:00
2015-01-24 23:39:43 +02:00
if ( get_query_var('profiletab') ) {
$this->active_tab = get_query_var('profiletab');
}
2016-03-15 16:29:43 -07:00
2015-03-01 00:44:04 +02:00
$this->active_tab = apply_filters( 'um_profile_active_tab', $this->active_tab );
2015-02-01 01:30:04 +02:00
return $this->active_tab;
}
2016-03-15 16:29:43 -07:00
2015-02-01 01:30:04 +02:00
/***
*** @Get active active_subnav
***/
function active_subnav() {
2016-03-15 16:29:43 -07:00
2015-02-01 01:30:04 +02:00
$this->active_subnav = null;
2016-03-15 16:29:43 -07:00
2015-01-24 23:39:43 +02:00
if ( get_query_var('subnav') ) {
$this->active_subnav = get_query_var('subnav');
}
2016-03-15 16:29:43 -07:00
2015-02-01 01:30:04 +02:00
return $this->active_subnav;
2014-12-29 15:51:55 +02:00
}
2016-03-15 16:29:43 -07:00
2015-01-24 23:39:43 +02:00
/***
*** @Show meta in profile
***/
2014-12-29 15:51:55 +02:00
function show_meta( $array ) {
2014-12-29 21:14:22 +02:00
global $ultimatemember;
2014-12-29 15:51:55 +02:00
$output = '';
2016-03-15 16:29:43 -07:00
2016-04-27 22:44:56 +08:00
if( isset( $array ) ){
foreach( $array as $key ) {
$data = '';
if ( $key && um_filtered_value( $key ) ) {
2016-03-15 16:29:43 -07:00
2016-04-27 22:44:56 +08:00
if ( isset( $ultimatemember->builtin->all_user_fields[$key]['icon'] ) ) {
$icon = $ultimatemember->builtin->all_user_fields[$key]['icon'];
} else {
$icon = '';
}
2016-03-15 16:29:43 -07:00
2016-04-27 22:44:56 +08:00
$icon = ( isset( $icon ) && !empty( $icon ) ) ? '<i class="'.$icon.'"></i>' : '';
2016-03-15 16:29:43 -07:00
2016-04-27 22:44:56 +08:00
if ( !um_get_option('profile_show_metaicon') )
$icon = '';
2016-03-15 16:29:43 -07:00
2016-04-27 22:44:56 +08:00
$value = um_filtered_value( $key );
2016-03-15 16:29:43 -07:00
2016-04-27 22:44:56 +08:00
$items[] = '<span>' . $icon . $value . '</span>';
$items[] = '<span class="b">&bull;</span>';
2014-12-29 15:51:55 +02:00
2016-04-27 22:44:56 +08:00
}
}
}
2014-12-29 15:51:55 +02:00
if ( isset( $items ) ) {
array_pop($items);
foreach( $items as $item ) {
$output .= $item;
}
}
return $output;
}
2016-03-15 16:29:43 -07:00
}