Files
ultimatemember/core/um-permalinks.php
T

236 lines
6.2 KiB
PHP
Raw Normal View History

2014-12-15 22:38:07 +02:00
<?php
class UM_Permalinks {
function __construct() {
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
global $wp;
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
$this->core = get_option('um_core_pages');
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
add_action('init', array(&$this, 'check_for_querystrings'), 1);
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
add_action('init', array(&$this, 'activate_account_via_email_link'), 1);
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
$this->current_url = $this->get_current_url();
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
}
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
/***
*** @Get query as array
***/
function get_query_array() {
$parts = parse_url( $this->get_current_url() );
2015-12-15 13:46:53 -08:00
if ( isset( $parts['query'] ) ) {
parse_str($parts['query'], $query);
return $query;
2015-01-23 19:03:29 +02:00
}
2014-12-15 22:38:07 +02:00
}
/***
*** @Get current URL anywhere
***/
function get_current_url( $no_query_params = false ) {
global $post;
2015-12-15 13:46:53 -08:00
2016-01-13 00:33:54 +02:00
$um_get_option = get_option('um_options');
$server_name_method = ( $um_get_option['current_url_method'] ) ? $um_get_option['current_url_method'] : 'SERVER_NAME';
$um_port_forwarding_url = ( isset( $um_get_option['um_port_forwarding_url'] ) ) ? $um_get_option['um_port_forwarding_url']: '';
2016-01-12 10:25:50 +08:00
2015-11-05 19:51:31 +08:00
if ( !isset( $_SERVER['SERVER_NAME'] ) )
return '';
2015-12-15 13:46:53 -08:00
if ( is_front_page() ) {
2015-04-25 21:41:47 +02:00
$page_url = home_url();
2015-12-15 13:46:53 -08:00
if( isset( $_SERVER['QUERY_STRING'] ) && trim( $_SERVER['QUERY_STRING'] ) ) {
$page_url .= '?' . $_SERVER['QUERY_STRING'];
}
} else {
2014-12-15 22:38:07 +02:00
$page_url = 'http';
2015-12-15 13:46:53 -08:00
if ( isset( $_SERVER["HTTPS"] ) && $_SERVER["HTTPS"] == "on" ) {
$page_url .= "s";
}
2014-12-15 22:38:07 +02:00
$page_url .= "://";
2015-12-15 13:46:53 -08:00
2016-01-12 10:25:50 +08:00
if ( $um_port_forwarding_url == 1 && isset( $_SERVER["SERVER_PORT"] ) ) {
2015-12-15 13:46:53 -08:00
$page_url .= $_SERVER[ $server_name_method ].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
2016-01-12 10:25:50 +08:00
2015-12-15 13:46:53 -08:00
} else {
$page_url .= $_SERVER[ $server_name_method ].$_SERVER["REQUEST_URI"];
}
2016-01-12 10:25:50 +08:00
2015-12-15 13:46:53 -08:00
}
2014-12-15 22:38:07 +02:00
if ( $no_query_params == true ) {
$page_url = strtok($page_url, '?');
}
2016-01-12 10:25:50 +08:00
2014-12-15 22:38:07 +02:00
return apply_filters( 'um_get_current_page_url', $page_url );
}
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
/***
*** @activates an account via email
***/
function activate_account_via_email_link(){
global $ultimatemember;
2015-04-07 20:10:23 +02:00
2015-03-07 13:07:49 +02:00
if ( isset($_REQUEST['act']) && $_REQUEST['act'] == 'activate_via_email' && isset($_REQUEST['hash']) && strlen($_REQUEST['hash']) == 40 &&
2014-12-15 22:38:07 +02:00
isset($_REQUEST['user_id']) && is_numeric($_REQUEST['user_id']) ) { // valid token
2015-12-15 13:46:53 -08:00
2015-05-18 14:12:50 +03:00
$user_id = absint( $_REQUEST['user_id'] );
delete_option( "um_cache_userdata_{$user_id}" );
2015-12-15 13:46:53 -08:00
2015-05-18 14:12:50 +03:00
um_fetch_user( $user_id );
2015-04-07 20:10:23 +02:00
2014-12-15 22:38:07 +02:00
if ( um_user('account_status') != 'awaiting_email_confirmation' ) wp_die('The activation link you used is invalid or has expired.');
2015-12-15 13:46:53 -08:00
2016-01-04 12:40:30 +08:00
if ( strtolower($_REQUEST['hash']) !== strtolower( um_user('account_secret_hash') ) ) wp_die('The secret key provided does not match this one for the user.');
2014-12-15 22:38:07 +02:00
$ultimatemember->user->approve();
2015-04-07 20:10:23 +02:00
$redirect = ( um_user('url_email_activate') ) ? um_user('url_email_activate') : um_get_core_page('login', 'account_active');
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
um_reset_user();
2015-12-15 13:46:53 -08:00
2015-11-05 19:51:31 +08:00
do_action('um_after_email_confirmation', $user_id );
2015-04-07 20:10:23 +02:00
exit( wp_redirect( $redirect ) );
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
}
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
}
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
/***
*** @makes an activate link for any user
***/
function activate_url(){
global $ultimatemember;
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
if ( !um_user('account_secret_hash') ) return false;
2015-12-15 13:46:53 -08:00
2015-04-25 21:41:47 +02:00
$url = add_query_arg( 'act', 'activate_via_email', home_url() );
$url = add_query_arg( 'hash', um_user('account_secret_hash'), $url );
$url = add_query_arg( 'user_id', um_user('ID'), $url );
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
return $url;
}
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
/***
*** @checks for UM query strings
***/
function check_for_querystrings(){
global $ultimatemember;
2015-12-15 13:46:53 -08:00
if ( isset($_REQUEST['message']) )
2014-12-15 22:38:07 +02:00
$ultimatemember->shortcodes->message_mode = true;
}
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
/***
*** @add a query param to url
***/
function add_query( $key, $value ) {
2015-11-05 19:51:31 +08:00
$this->current_url = add_query_arg( $key, $value, $this->current_url );
2014-12-15 22:38:07 +02:00
return $this->current_url;
}
/***
*** @remove a query param from url
***/
function remove_query( $key, $value ) {
$this->current_url = remove_query_arg( $key, $this->current_url );
return $this->current_url;
}
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
/***
*** @get profile url for set user
***/
function profile_url() {
global $ultimatemember;
2015-04-07 20:10:23 +02:00
2015-11-05 19:51:31 +08:00
$page_id = $this->core['user'];
$profile_url = get_permalink( $page_id );
2015-12-15 13:46:53 -08:00
2015-11-05 19:51:31 +08:00
if ( function_exists('icl_get_current_language') && icl_get_current_language() != icl_get_default_language() ) {
if ( get_the_ID() > 0 && get_post_meta( get_the_ID(), '_um_wpml_user', true ) == 1 ) {
$profile_url = get_permalink( get_the_ID() );
}
}
2015-12-15 13:46:53 -08:00
2016-01-10 22:30:57 +08:00
// WPML compatibility
if ( function_exists('icl_object_id') ) {
$language_code = ICL_LANGUAGE_CODE;
$lang_post_id = icl_object_id( $page_id , 'page', true, $language_code );
if($lang_post_id != 0) {
$profile_url = get_permalink( $lang_post_id );
}else {
// No page found, it's most likely the homepage
global $sitepress;
$profile_url = $sitepress->language_url( $language );
}
}
2014-12-15 22:38:07 +02:00
if ( um_get_option('permalink_base') == 'user_login' ) {
2015-01-24 23:39:43 +02:00
$user_in_url = um_user('user_login');
2015-12-15 13:46:53 -08:00
2015-01-25 19:59:18 +02:00
if ( is_email($user_in_url) ) {
$user_in_url = str_replace('@','',$user_in_url);
if( ( $pos = strrpos( $user_in_url , '.' ) ) !== false ) {
$search_length = strlen( '.' );
$user_in_url = substr_replace( $user_in_url , '-' , $pos , $search_length );
}
2015-02-04 20:31:39 +02:00
} else {
2015-12-15 13:46:53 -08:00
2015-02-04 20:31:39 +02:00
$user_in_url = sanitize_title( $user_in_url );
2015-01-25 19:59:18 +02:00
}
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
}
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
if ( um_get_option('permalink_base') == 'user_id' ) {
$user_in_url = um_user('ID');
}
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
if ( um_get_option('permalink_base') == 'name' ) {
2016-01-13 12:33:21 +08:00
$user_in_url = rawurlencode( strtolower( str_replace(" ",".",um_user('full_name') ) ) );
}
if ( um_get_option('permalink_base') == 'name_dash' ) {
$user_in_url = rawurlencode( strtolower( str_replace(" ","-",um_user('full_name') ) ) );
}
if ( um_get_option('permalink_base') == 'name_plus' ) {
$user_in_url = strtolower( str_replace(" ","+",um_user('full_name') ) );
2014-12-15 22:38:07 +02:00
}
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
if ( get_option('permalink_structure') ) {
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
$profile_url = trailingslashit( untrailingslashit( $profile_url ) );
$profile_url = $profile_url . $user_in_url . '/';
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
} else {
2015-12-15 13:46:53 -08:00
2015-04-25 21:41:47 +02:00
$profile_url = add_query_arg( 'um_user', $user_in_url, $profile_url );
2015-12-15 13:46:53 -08:00
2014-12-15 22:38:07 +02:00
}
2015-01-25 19:59:18 +02:00
2014-12-15 22:38:07 +02:00
return $profile_url;
}
2015-12-15 13:46:53 -08:00
2015-01-03 15:31:15 +02:00
/***
*** @get action url for admin use
***/
function admin_act_url( $action, $subaction ) {
$url = $this->get_current_url();
2015-04-25 21:41:47 +02:00
$url = add_query_arg( 'um_adm_action', $action, $url );
$url = add_query_arg( 'sub', $subaction, $url );
$url = add_query_arg( 'user_id', um_user('ID'), $url );
2015-01-03 15:31:15 +02:00
return $url;
}
2014-12-15 22:38:07 +02:00
2015-12-15 13:46:53 -08:00
}