Guest User

api.php -- userpro/functions

a guest
Jan 31st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 100.27 KB | None | 0 0
  1. <?php
  2.  
  3. class userpro_api {
  4.  
  5.     var $twitter;
  6.     var $twitter_url;
  7.     var $google, $googleplus, $googleoauth2, $_google_user_cache;
  8.  
  9.     function __construct() {
  10.  
  11.         $this->temp_id = null;
  12.  
  13.         $this->upload_dir = wp_upload_dir();
  14.        
  15.         $this->upload_base_dir = $this->upload_dir['basedir'];
  16.         if ( strstr( $this->upload_base_dir, 'wp-content/uploads/sites' ) ) {
  17.             $this->upload_base_dir = $this->str_before( $this->upload_base_dir, '/wp-content/uploads/sites' );
  18.             $this->upload_base_dir = $this->upload_base_dir . '/wp-content/uploads/userpro/';
  19.         } else {
  20.             $this->upload_base_dir = $this->upload_base_dir . '/userpro/';
  21.         }
  22.        
  23.         $this->upload_base_url = $this->upload_dir['baseurl'];
  24.         if ( strstr( $this->upload_base_url, 'wp-content/uploads/sites' ) ) {
  25.             $this->upload_base_url = $this->str_before( $this->upload_base_url, '/wp-content/uploads/sites' );
  26.             $this->upload_base_url = $this->upload_base_url . '/wp-content/uploads/userpro/';
  27.         } else {
  28.             $this->upload_base_url = $this->upload_base_url . '/userpro/';
  29.         }
  30.        
  31.         $this->upload_path_wp = trailingslashit($this->upload_dir['path']);
  32.         $this->upload_path = $this->upload_dir['basedir'] . '/userpro/';
  33.         $this->badges_url = userpro_url . 'img/badges/';
  34.        
  35.         $this->fields = get_option('userpro_fields');
  36.         $this->groups = get_option('userpro_fields_groups');
  37.         $this->get_cached_results = (array) get_option('userpro_cached_results');
  38.        
  39.        
  40.         add_action('init', array(&$this, 'load_twitter'), 9);
  41.        
  42.         add_action('init', array(&$this, 'twitter_authorize'), 10);
  43.        
  44.         add_action('init', array(&$this, 'load_google'), 11);
  45.        
  46.         add_action('init', array(&$this, 'google_authorize'), 12);
  47.        
  48.         add_action('init',  array(&$this, 'trial_version'), 9);
  49.  
  50.         add_action('init', array(&$this, 'linkedin_authorize'));
  51.  
  52.         add_action('init', array(&$this, 'instagram_authorize'));
  53.        
  54.         add_action('init',  array(&$this, 'process_email_approve'), 9);
  55.        
  56.         add_action('init',  array(&$this, 'process_verification_invites'), 9);
  57.        
  58.         add_action('wp',  array(&$this, 'update_online_users'), 9);
  59.        
  60.         /* Export settings */
  61.         add_action('template_redirect', array(&$this, 'admin_redirect_download_files') );
  62.         add_filter('init', array(&$this,'add_query_var_vars') );
  63.        
  64.         delete_option('get_twitter_auth_url');
  65.        
  66.     }
  67.    
  68.     /******************************************
  69.     Delete a File Permanently
  70.     ******************************************/
  71.     function delete_file($user_id, $key){
  72.         if ( userpro_profile_data( $key, $user_id ) ) {
  73.             $file = $this->get_uploads_dir($user_id) . basename( userpro_profile_data( $key, $user_id ) );
  74.             if (file_exists($file)) {
  75.                 unlink($file);
  76.             }
  77.         }
  78.     }
  79.    
  80.     /******************************************
  81.     Parse a single memberlist table column
  82.     ******************************************/
  83.     function parse_column($col, $user_id, $user, $args) {
  84.         global $userpro_msg;
  85.         $output = null;
  86.        
  87.         $show_on_mobile = array('');
  88.         if (isset($args['show_on_mobile'])) {
  89.             $show_on_mobile = explode(',',$args['show_on_mobile']);
  90.         }
  91.        
  92.         switch($col) {
  93.             case 'user_id':
  94.                 if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  95.                 $output .= '<td class="small '.$col.' '.$mobile.'">'.$user_id.'</td>';
  96.                 break;
  97.             case 'picture':
  98.                 if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  99.                 $output .= '<td class="thumb '.$col.' '.$mobile.'"><div class="userpro-table-img"><a href="'.$this->permalink($user_id).'">'.get_avatar($user_id, 36).'</a></div></td>';
  100.                 break;
  101.             case 'name' :
  102.                 if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  103.                 $output .= '<td class="name '.$col.' '.$mobile.'"><a href="'.$this->permalink($user_id).'">' . userpro_profile_data('user_login', $user_id).'</a> ';
  104.                 if ( userpro_is_verified($user_id) ) $output .= userpro_get_badge('verified');
  105.                 $output .= '<br /><span class="nickname">('. userpro_profile_data('display_name', $user_id).')</span></td>';
  106.                 break;
  107.             case 'country':
  108.                 if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  109.                 $output .= '<td class="'.$col.' '.$mobile.'">'.userpro_get_badge('country_big', $user_id).'</td>';
  110.                 break;
  111.             case 'gender':
  112.                 if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  113.                 $output .= '<td class="'.$col.' '.$mobile.'">'.$this->cap_gender($user_id).'</td>';
  114.                 break;
  115.             case 'role':
  116.                 if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  117.                 $output .= '<td class="'.$col.' '.$mobile.'">'.$this->get_role_nice($user).'</td>';
  118.                 break;
  119.             case 'email_user':
  120.                 if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  121.                 $output .= '<td class="'.$col.' '.$mobile.'">';
  122.                 if ( userpro_field_is_viewable('user_email', $user_id, $args) ) $output .= '<a href="mailto:'.userpro_profile_data('user_email', $user_id).'" class="userpro-flat-btn"><i class="userpro-icon-envelope"></i><span>'.__('Contact','userpro').'</span></a>';
  123.                 $output .= '</td>';
  124.                 break;
  125.             case 'message_user':
  126.                 if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  127.                 if (class_exists('userpro_msg_api')) {
  128.                     if ( $userpro_msg->can_chat_with( $user_id ) ) {
  129.                         $output .= '<td class="'.$col.' '.$mobile.'"><a href="#" class="userpro-flat-btn chat userpro-init-chat" data-chat_with="'.$user_id.'" data-chat_from="'.get_current_user_id().'"><i class="userpro-icon-comment"></i><span>'.__('Send Message','userpro-msg').'</span>';
  130.                         $output .= '</a></td>';
  131.                     }
  132.                 }
  133.                 break;
  134.             default:
  135.            
  136.                 $value = get_user_meta($user_id, $col, true);
  137.                 if (is_array($value)){
  138.                     $value = implode(',', $value);
  139.                 }
  140.                
  141.                 if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  142.                 $output .= '<td class="'.$col.' '.$mobile.'">'.$value.'</td>';
  143.                
  144.                 break;
  145.         }
  146.        
  147.         return $output;
  148.     }
  149.        
  150.     /******************************************
  151.     Parse memberlist table columns
  152.     ******************************************/
  153.     function parse_columns($type,$cols, $args) {
  154.         $output = null;
  155.         $col_content = null;
  156.         if ($type == 'thead') {
  157.             $output .= '<thead><tr>{columns}</tr></thead>';
  158.         } else {
  159.             $output .= '<tfoot><tr>{columns}</tr></tfoot>';
  160.         }
  161.        
  162.         $show_on_mobile = array('');
  163.         if (isset($args['show_on_mobile'])) {
  164.             $show_on_mobile = explode(',',$args['show_on_mobile']);
  165.         }
  166.        
  167.         $cols = explode(',',$cols);
  168.         foreach($cols as $col) {
  169.             switch($col) {
  170.                 case 'user_id' :
  171.                     if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  172.                     $col_content .= '<th class="small '.$mobile.'">'.__('ID','userpro').'</th>';
  173.                     break;
  174.                 case 'picture' :
  175.                     if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  176.                     $col_content .= '<th class="thumb '.$mobile.'">'.__('Photo','userpro').'</th>';
  177.                     break;
  178.                 case 'name' :
  179.                     if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  180.                     $col_content .= '<th class="name '.$mobile.'">'.__('Username','userpro').'</th>';
  181.                     break;
  182.                 case 'country' :
  183.                     if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  184.                     $col_content .= '<th class="'.$mobile.'">'.__('Location','userpro').'</th>';
  185.                     break;
  186.                 case 'gender' :
  187.                     if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  188.                     $col_content .= '<th class="'.$mobile.'">'.__('Sex','userpro').'</th>';
  189.                     break;
  190.                 case 'role' :
  191.                     if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  192.                     $col_content .= '<th class="'.$mobile.'">'.__('Role','userpro').'</th>';
  193.                     break;
  194.                 case 'email_user' :
  195.                     if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  196.                     $col_content .= '<th class="'.$mobile.'">'.__('Contact','userpro').'</th>';
  197.                     break;
  198.                 case 'message_user' :
  199.                     if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  200.                     $col_content .= '<th class="'.$mobile.'">'.__('Send Message','userpro').'</th>';
  201.                     break;
  202.                 default:
  203.                     if ( in_array($col, $show_on_mobile)) {$mobile = 'show-on-mobile';} else {$mobile = 'hide-on-mobile';}
  204.                     $col_content .= '<th class="'.$mobile.'">'.$this->field_label($col).'</th>';
  205.                     break;
  206.             }
  207.         }
  208.         $output = str_replace('{columns}',$col_content,$output);
  209.         return $output;
  210.     }
  211.    
  212.     /******************************************
  213.     Gender capital
  214.     ******************************************/
  215.     function cap_gender($user_id) {
  216.         $gender = get_user_meta($user_id, 'gender', true);
  217.         if ($gender) {
  218.             return ucfirst($gender);
  219.         }
  220.     }
  221.    
  222.    
  223.    
  224.     /******************************************
  225.     Get need before in string
  226.     ******************************************/
  227.     function str_before($subject, $needle)
  228.     {
  229.         $p = strpos($subject, $needle);
  230.         return substr($subject, 0, $p);
  231.     }
  232.    
  233.     /******************************************
  234.     Profile photo label
  235.     ******************************************/
  236.     function profile_photo_title( $user_id ) {
  237.         if ($user_id && userpro_profile_data( 'profilepicture', $user_id ) ) {
  238.             $title = sprintf(__('%s\'s profile photo','userpro'), userpro_profile_data('display_name',$user_id));
  239.         } else {
  240.             if ( userpro_get_option('use_default_avatars') == 1 ) {
  241.                 $title = sprintf(__('%s\'s profile photo','userpro'), userpro_profile_data('display_name',$user_id));
  242.             } else {
  243.                 $title = sprintf(__('%s did not upload a photo yet.','userpro'), userpro_profile_data('display_name',$user_id));
  244.             }
  245.         }
  246.         return $title;
  247.     }
  248.    
  249.     /******************************************
  250.     Get Image URL
  251.     ******************************************/
  252.     function get_image_url_by_html($get_avatar){
  253.         preg_match("/src='(.*?)'/i", $get_avatar, $matches);
  254.         return $matches[1];
  255.     }
  256.    
  257.     /******************************************
  258.     Full profile photo url
  259.     ******************************************/
  260.     function profile_photo_url( $user_id ) {
  261.         if ($user_id && userpro_profile_data( 'profilepicture', $user_id ) ) {
  262.             $url = userpro_profile_data( 'profilepicture', $user_id );
  263.         } else {
  264.             if ( userpro_get_option('use_default_avatars') == 1 ) {
  265.                 $url = $this->get_image_url_by_html( get_avatar( $user_id, 150 ) );
  266.             } else {
  267.                 if ($user_id && userpro_profile_data( 'gender', $user_id ) ) {
  268.                     $gender = strtolower( userpro_profile_data( 'gender', $user_id ) );
  269.                 } else {
  270.                     $gender = 'male'; // default gender
  271.                 }
  272.                 $url = userpro_url . 'img/default_avatar_'.$gender.'.jpg';
  273.             }
  274.         }
  275.         return $url;
  276.     }
  277.    
  278.     /******************************************
  279.     Time elapsed format
  280.     ******************************************/
  281.     function time_elapsed($ptime){
  282.        
  283.         $etime = current_time('timestamp') - $ptime;
  284.  
  285.         if ($etime < 1)
  286.         {
  287.             return __('now!','userpro');
  288.         }
  289.  
  290.         $a = array( 12 * 30 * 24 * 60 * 60  =>  __('year','userpro'),
  291.                     30 * 24 * 60 * 60       =>  __('month','userpro'),
  292.                     24 * 60 * 60            =>  __('day','userpro'),
  293.                     60 * 60                 =>  __('hour','userpro'),
  294.                     60                      =>  __('minute','userpro'),
  295.                     1                       =>  __('second','userpro')
  296.                     );
  297.  
  298.         foreach ($a as $secs => $str)
  299.         {
  300.             $d = $etime / $secs;
  301.             if ($d >= 1)
  302.             {
  303.                 $r = round($d);
  304.                 return $r . ' ' . $str . ($r > 1 ? 's' : '') . __(' ago','userpro');
  305.             }
  306.         }
  307.     }
  308.    
  309.     /******************************************
  310.     Set default options (accepts array)
  311.     ******************************************/
  312.     function set_defaults($array, $extension=false){
  313.         $defaults = userpro_default_options();
  314.         if ($extension == 'social'){
  315.             $defaults = userpro_sc_default_options();
  316.         }
  317.         foreach($array as $key) {
  318.             userpro_set_option( $key , $defaults[$key]);
  319.         }
  320.     }
  321.    
  322.     /******************************************
  323.     friendly username
  324.     ******************************************/
  325.     function clean_user($string){
  326.         $string = strtolower($string);
  327.         $string = preg_replace("/[^a-z0-9_\s-]/", "", $string);
  328.         $string = preg_replace("/[\s-]+/", " ", $string);
  329.         $string = preg_replace("/[\s_]/", "_", $string);
  330.         return $string;
  331.     }
  332.    
  333.     /******************************************
  334.     Make display_name unique
  335.     ******************************************/
  336.     function unique_display_name($display_name){
  337.         $r = str_shuffle("0123456789");
  338.         $r1 = (int) $r[0];
  339.         $r2 = (int) $r[1];
  340.         $display_name = $display_name . $r1 . $r2;
  341.         return $display_name;
  342.     }
  343.    
  344.     /******************************************
  345.     Make username unique
  346.     ******************************************/
  347.     function unique_user($service=null,$form=null){
  348.         if ($service){
  349.             if ($service == 'google') {
  350.                 if (isset($form['name']) && is_array($form['name'])) {
  351.                     $name = $form['name']['givenName'] . ' ' . $form['name']['familyName'];
  352.                     $username = $this->clean_user($name);
  353.                 } elseif ( isset($form['displayName']) && !empty($form['displayName']) ) {
  354.                     $username = $this->clean_user($form['displayName']);
  355.                 } else {
  356.                     $username = $form['id'];
  357.                 }
  358.             }
  359.             if ($service == 'twitter') {
  360.                 if (isset($form['screen_name']) && !empty($form['screen_name']) ) {
  361.                     $username = $form['screen_name'];
  362.                 }
  363.             }
  364.             if ($service == 'vk') {
  365.                 if (isset($form['screen_name']) && !empty($form['screen_name']) ) {
  366.                     $username = $form['screen_name'];
  367.                 } else {
  368.                     $username = $form['uid'];
  369.                 }
  370.             }
  371.         }
  372.        
  373.         // make sure username is unique
  374.         if (username_exists($username)){
  375.             $r = str_shuffle("0123456789");
  376.             $r1 = (int) $r[0];
  377.             $r2 = (int) $r[1];
  378.             $username = $username . $r1 . $r2;
  379.         }
  380.         if (username_exists($username)){
  381.             $r = str_shuffle("0123456789");
  382.             $r1 = (int) $r[0];
  383.             $r2 = (int) $r[1];
  384.             $username = $username . $r1 . $r2;
  385.         }
  386.         return $username;
  387.     }
  388.    
  389.     /******************************************
  390.     Load Google
  391.     ******************************************/
  392.     function load_google(){
  393.         if ( userpro_get_option('google_connect') == 1 && userpro_get_option('google_client_id') && userpro_get_option('google_client_secret') && userpro_get_option('google_redirect_uri') ) {
  394.                 if( !class_exists( 'apiClient' ) ) { // loads the Google class
  395.                     require_once ( userpro_path . 'lib/google/src/apiClient.php' );
  396.                 }
  397.                 if( !class_exists( 'apiPlusService' ) ) { // Loads the google plus service class for user data
  398.                     require_once ( userpro_path . 'lib/google/src/contrib/apiPlusService.php' );
  399.                 }
  400.                 if( !class_exists( 'apiOauth2Service' ) ) { // loads the google plus service class for user email
  401.                     require_once ( userpro_path . 'lib/google/src/contrib/apiOauth2Service.php' );
  402.                 }
  403.                
  404.                 // Google Objects
  405.                 $this->google = new apiClient();
  406.                 $this->google->setApplicationName( "Google+ PHP Starter Application" );
  407.                 $this->google->setClientId( userpro_get_option('google_client_id') );
  408.                 $this->google->setClientSecret( userpro_get_option('google_client_secret') );
  409.                 $this->google->setRedirectUri( userpro_get_option('google_redirect_uri') );
  410.                 $this->google->setScopes( array( 'https://www.googleapis.com/auth/plus.me','https://www.googleapis.com/auth/userinfo.email' ) );
  411.                 $this->google->setApprovalPrompt('auto') ;
  412.                 $this->googleplus = new apiPlusService( $this->google ); // For getting user detail from google
  413.                 $this->googleoauth2 = new apiOauth2Service( $this->google ); // For gettting user email from google
  414.                
  415.                 if (isset($_SESSION['google_token'])) {
  416.                     $this->google->setAccessToken($_SESSION['google_token']);
  417.                 }
  418.        
  419.         }
  420.     }
  421.    
  422.     /******************************************
  423.     Google auth url
  424.     ******************************************/
  425.     function get_google_auth_url(){
  426.             //load google class
  427.             $google = $this->load_google();
  428.             $url = $this->google->createAuthUrl();
  429.             $authurl = isset( $url ) ? $url : '';
  430.             return $authurl;
  431.     }
  432.    
  433.     /******************************************
  434.     Google auth ($_REQUEST)
  435.     ******************************************/
  436.     function google_authorize(){
  437.         if ( userpro_get_option('google_connect') == 1 && userpro_get_option('google_client_id') && userpro_get_option('google_client_secret') && userpro_get_option('google_redirect_uri') ) {
  438.             if( isset( $_GET['code'] ) && isset($_REQUEST['upslug']) && $_REQUEST['upslug'] == 'gplus' ) {
  439.            
  440.                 //load google class
  441.                 $google = $this->load_google();
  442.  
  443.                 if (isset($_SESSION['google_token'])) {
  444.                     $gplus_access_token = $_SESSION['google_token'];
  445.                 } else {
  446.                     $google_token = $this->google->authenticate();
  447.                     $_SESSION['google_token'] = $google_token;
  448.                     $gplus_access_token = $_SESSION['google_token'];
  449.                 }
  450.                
  451.                 //check access token is set or not
  452.                 if ( !empty( $gplus_access_token ) ) {
  453.                
  454.                     // capture data
  455.                     $user_info = $this->googleplus->people->get('me');
  456.                     $user_email = $this->googleoauth2->userinfo->get(); // to get email
  457.                     $user_info['email'] = $user_email['email'];
  458.                    
  459.                     //if user data get successfully
  460.                     if (isset($user_info['id'])){
  461.                        
  462.                         $data['user'] = $user_info;
  463.                        
  464.                         //all data will assign to a session
  465.                         $_SESSION['google_user_cache'] = $data;
  466.  
  467.                         $users = get_users(array(
  468.                             'meta_key'     => 'userpro_google_id',
  469.                             'meta_value'   => $user_info['id'],
  470.                             'meta_compare' => '='
  471.                         ));
  472.                         if (isset($users[0]->ID) && is_numeric($users[0]->ID) ){
  473.                             $returning = $users[0]->ID;
  474.                             $returning_user_login = $users[0]->user_login;
  475.                         } else {
  476.                             $returning = '';
  477.                         }
  478.                         // Authorize user
  479.                         if (userpro_is_logged_in()) {
  480.                             $this->update_google_id( get_current_user_id(), $user_info['id'] );
  481.                                
  482.                             if (userpro_get_option('google_signin_redirect')){
  483.                                 wp_safe_redirect( userpro_get_option('google_signin_redirect') );
  484.                             }elseif(userpro_get_option('after_login') == 'no_redirect'){
  485.                                    
  486.                                     $redirect_uri =$_SESSION['current_page_uri'];
  487.                                     wp_safe_redirect( $redirect_uri );
  488.                                     exit;
  489.                                 }
  490.                           else {
  491.                                 wp_safe_redirect( $this->permalink() );
  492.                             }
  493.                        
  494.                         } else {
  495.                             if ( $returning != '' ) {
  496.                                
  497.                                     if(!get_user_meta( $returning, 'userpro_account_status' , true)){
  498.                                 userpro_auto_login( $returning_user_login, true );     
  499.                                
  500.                                 if (userpro_get_option('google_signin_redirect')){
  501.                                     wp_safe_redirect( userpro_get_option('google_signin_redirect') );
  502.                             }elseif(userpro_get_option('after_login') == 'no_redirect'){
  503.                                    
  504.                                     $redirect_uri =$_SESSION['current_page_uri'];
  505.                                     wp_safe_redirect( $redirect_uri );
  506.                                     exit;
  507.                                 }
  508.                           else {
  509.                                     wp_safe_redirect( $this->permalink() );
  510.                                 }
  511.                             }else{
  512.                             add_action('userpro_pre_form_message', 'userpro_msg_block_account');
  513.                             }
  514.                             } else if ($user_info['email'] != '' && email_exists($user_info['email'])) {   
  515.                                
  516.                                 $user_id = email_exists( $user_info['email'] );
  517.                                 $user = get_userdata($user_id);
  518.                                
  519.                                 if(!get_user_meta( $user_id, 'userpro_account_status' , true)){
  520.                                 userpro_auto_login( $user->user_login, true );
  521.                                 $this->update_google_id($user_id, $user_info['id']);
  522.                                
  523.                                 if (userpro_get_option('google_signin_redirect')){
  524.                                     wp_safe_redirect( userpro_get_option('google_signin_redirect') );
  525.                             }elseif(userpro_get_option('after_login') == 'no_redirect'){
  526.                                    
  527.                                     $redirect_uri =$_SESSION['current_page_uri'];
  528.                                     wp_safe_redirect( $redirect_uri );
  529.                                     exit;
  530.                                 }
  531.                           else {
  532.                                     wp_safe_redirect( $this->permalink() );
  533.                                 }
  534.                 }else{
  535.                 add_action('userpro_pre_form_message', 'userpro_msg_block_account');
  536.                 }
  537.                             } else {
  538.                            
  539.                                 $user_pass = wp_generate_password( $length=12, $include_standard_special_chars=false );
  540.                                 $unique_user = $this->unique_user('google', $user_info);
  541.                                 $user_id = $this->new_user( $unique_user , $user_pass, '', $user_info, $type='google' );
  542.                                 userpro_auto_login( $unique_user, true );
  543.                                
  544.                             if (userpro_get_option('google_signin_redirect')){
  545.                                     wp_safe_redirect( userpro_get_option('google_signin_redirect') );
  546.                             }elseif(userpro_get_option('after_login') == 'no_redirect'){
  547.                                    
  548.                                     $redirect_uri =$_SESSION['current_page_uri'];
  549.                                     wp_safe_redirect( $redirect_uri );
  550.                                     exit;
  551.                                 }
  552.                           else {
  553.                                     wp_safe_redirect( $this->permalink() );
  554.                                 }
  555.                                
  556.                             }
  557.                         }
  558.                     }
  559.                    
  560.                 }
  561.            
  562.             }
  563.         }
  564.     }
  565.    
  566.     /******************************************
  567.     Load twitter
  568.     ******************************************/
  569.     function load_twitter(){
  570.         if ( userpro_get_option('twitter_connect') == 1 && userpro_get_option('twitter_consumer_key') && userpro_get_option('twitter_consumer_secret') ) {
  571.        
  572.             if (!session_id()){
  573.                 session_start();
  574.             }
  575.             if (!class_exists('TwitterOAuth')){
  576.                 require_once( userpro_path . 'lib/twitteroauth/twitteroauth.php');
  577.             }
  578.            
  579.             $this->twitter = new TwitterOAuth(  userpro_get_option('twitter_consumer_key') , userpro_get_option('twitter_consumer_secret') );
  580.            
  581.         }
  582.     }
  583.    
  584.     /******************************************
  585.     Twitter redirection url after connect
  586.     ******************************************/
  587.     function twitter_redirect_url(){
  588.         global $userpro;
  589.         $rules = get_option('userpro_redirects_login');
  590.        
  591.         if(isset($rules)){
  592.             $redirect_uri = $userpro->permalink();
  593.             $redirect_uri = apply_filters('userpro_login_redirect', $userpro->permalink());
  594.          
  595.         }else
  596.         {
  597.         $redirect_uri = remove_query_arg( array( 'oauth_token', 'oauth_verifier' ), esc_url($this->get_current_page_url()) );
  598.        
  599.         }
  600.         return $redirect_uri;
  601.     }
  602.    
  603.     /******************************************
  604.     Twitter auth url
  605.     ******************************************/
  606.     function get_twitter_auth_url() {
  607.            
  608.         global $post;
  609.        
  610.         if (!get_option('get_twitter_auth_url')){
  611.              
  612.             $request_token = $this->twitter->getRequestToken( $this->twitter_redirect_url() ); // user will be redirected here
  613.            
  614.             switch( $this->twitter->http_code ) {
  615.                 case 200:
  616.                     /* Commented by Ranjith */
  617.                    
  618.                     if(userpro_get_option('twitter_fix')=='a')
  619.                     {      
  620.                     $_SESSION['twt_oauth_token'] = $request_token['oauth_token'];
  621.                     $_SESSION['twt_oauth_token_secret'] = $request_token['oauth_token_secret'];
  622.                     }
  623.                     else
  624.                     {
  625.                         setcookie("twt_oauth_token", $request_token['oauth_token'], time()+3600, COOKIEPATH, COOKIE_DOMAIN);
  626.                         setcookie("twt_oauth_token_secret", $request_token['oauth_token_secret'], time()+3600, COOKIEPATH, COOKIE_DOMAIN);
  627.                     }                      
  628.                     $token = $request_token['oauth_token'];
  629.                     $this->twitter_url = $this->twitter->getAuthorizeURL( $token );                        
  630.                     break;
  631.                 default:
  632.                     $this->twitter_url = '';
  633.             }
  634.             update_option('get_twitter_auth_url', $this->twitter_url);
  635.             return $this->twitter_url;
  636.        
  637.         } else {
  638.             return get_option('get_twitter_auth_url');
  639.         }
  640.     }
  641.    
  642.     /******************************************
  643.     Twitter auth ($_REQUEST)
  644.     ******************************************/
  645.    
  646.     function twitter_authorize(){
  647.        
  648.         global $userpro;
  649.    
  650.         if ( userpro_get_option('twitter_connect') == 1 && userpro_get_option('twitter_consumer_key') && userpro_get_option('twitter_consumer_secret') ) {
  651.             //when user is going to logged in in twitter and verified successfully session will create
  652.             if ( isset( $_REQUEST['oauth_verifier'] ) && isset( $_REQUEST['oauth_token'] ) ) {
  653.                 //load twitter class
  654.                 $this->load_twitter();
  655.                
  656.                 if(userpro_get_option('twitter_fix')=='a')
  657.                 {                      
  658.                  $oauth_token = $_SESSION['twt_oauth_token'];
  659.                  $oauth_token_secret = $_SESSION['twt_oauth_token_secret'];
  660.                 }
  661.                 else
  662.                 {
  663.                     $oauth_token = $_COOKIE['twt_oauth_token'];
  664.                     $oauth_token_secret = $_COOKIE['twt_oauth_token_secret'];
  665.                 }
  666.  
  667.                 if( isset( $oauth_token ) && $oauth_token == $_REQUEST['oauth_token'] ) {
  668.  
  669.                     $this->twitter = new TwitterOAuth( userpro_get_option('twitter_consumer_key') , userpro_get_option('twitter_consumer_secret'), $oauth_token, $oauth_token_secret );
  670.                    
  671.                     // Request access tokens from twitter
  672.                     $tw_access_token = $this->twitter->getAccessToken($_REQUEST['oauth_verifier']);
  673.                    
  674.                     //session create for access token & secrets    
  675.                     $_SESSION['twt_oauth_token'] = $tw_access_token['oauth_token'];
  676.                     $_SESSION['twt_oauth_token_secret'] = $tw_access_token['oauth_token_secret'];
  677.                     $verifier['oauth_verifier'] = $_REQUEST['oauth_verifier'];
  678.                     $_SESSION[ 'twt_user_cache' ] = $verifier;
  679.                    
  680.                     //getting user data from twitter
  681.                     $user_info = $this->twitter->get('https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true');
  682.                     $user_info = (array)$user_info;
  683.                                        
  684.                     //if user data get successfully
  685.                     if (isset($user_info['id'])){
  686.                        
  687.                         $data['user'] = $user_info;
  688.                        
  689.                         //all data will assign to a session
  690.                         $_SESSION['twt_user_cache'] = $data;
  691.  
  692.                         $users = get_users(array(
  693.                             'meta_key'     => 'twitter_oauth_id',
  694.                             'meta_value'   => $user_info['id'],
  695.                             'meta_compare' => '='
  696.                         ));
  697.                         if (isset($users[0]->ID) && is_numeric($users[0]->ID) ){
  698.                             $returning = $users[0]->ID;
  699.                             $returning_user_login = $users[0]->user_login;
  700.                         } else {
  701.                             $returning = '';
  702.                         }
  703.                        
  704.                         // Authorize user
  705.                         if (userpro_is_logged_in()) {
  706.                             $this->update_twitter_id( get_current_user_id(), $user_info['id'] );
  707.                            
  708.                             if (userpro_get_option('twitter_signin_redirect')){
  709.                                 wp_safe_redirect( userpro_get_option('twitter_signin_redirect') );
  710.                             } elseif (userpro_get_option('after_login') == 'no_redirect') {
  711.                                 $redirect_uri =$_SESSION['current_page_uri'];
  712.                                 wp_safe_redirect( $redirect_uri );
  713.                                 exit;
  714.                             }else{ 
  715.                                 wp_safe_redirect( $this->permalink() );
  716.                             }
  717.                                
  718.                         }
  719.                         elseif ( $returning != '' ) {
  720.                                 if(!get_user_meta( $returning, 'userpro_account_status' , true)){
  721.                                 userpro_auto_login( $returning_user_login, true );     
  722.                                 $rules =get_option('userpro_redirects_login');
  723.                                                                
  724.                                 if(!empty($rules))
  725.                                 {
  726.                                     $redirect_uri = $userpro->permalink();                         
  727.                                     $redirect_uri = apply_filters('userpro_login_redirect',$userpro->permalink());
  728.  
  729.                                     wp_safe_redirect($redirect_uri);           
  730.                                 }
  731.                                 else if ( userpro_get_option('twitter_signin_redirect')){
  732.                                     wp_safe_redirect( userpro_get_option('twitter_signin_redirect') );
  733.                                 } elseif (userpro_get_option('after_login') == 'no_redirect') {
  734.                                     $redirect_uri =$_SESSION['current_page_uri'];
  735.                                    
  736.                                     wp_safe_redirect( $redirect_uri );
  737.                                     exit;
  738.                                 }else{ 
  739.                                     wp_safe_redirect( $this->permalink() );
  740.                                 }
  741.                             }else{
  742.                             add_action('userpro_pre_form_message', 'userpro_msg_block_account');
  743.                             }
  744.                             }
  745.                             else if ($user_info['screen_name'] != '' && username_exists($user_info['screen_name'])) {  
  746.                                 $user_id = username_exists( $user_info['screen_name'] );
  747.                                 $user = get_userdata($user_id);
  748.                                 if(!get_user_meta( $user_id, 'userpro_account_status' , true)){
  749.                                 userpro_auto_login( $user->user_login, true );
  750.                                 $this->update_twitter_id($user_id, $user_info['id']);
  751.                                
  752.                                 if (userpro_get_option('twitter_signin_redirect')){
  753.                                     wp_safe_redirect( userpro_get_option('twitter_signin_redirect') );
  754.                             } elseif (userpro_get_option('after_login') == 'no_redirect') {
  755.                                 $redirect_uri =$_SESSION['current_page_uri'];
  756.                                 wp_safe_redirect( $redirect_uri );
  757.                                 exit;
  758.                             }else{ 
  759.                                     wp_safe_redirect( $this->permalink() );
  760.                                 }
  761.                             }else{
  762.                             add_action('userpro_pre_form_message', 'userpro_msg_block_account');
  763.                             }
  764.                             }
  765.                             /* Twitter - Email is same - connect the user  */
  766.                             else if (isset ($user_info['email']) && $user_info['email'] != '' && email_exists($user_info['email']) ) {
  767.                            
  768.                                 $user_id = email_exists($user_info['email']);
  769.                                 $user = get_userdata($user_id);
  770.                                 update_user_meta($user_id, 'twitter_oauth_id',$user_info['id']);
  771.                                 userpro_auto_login( $unique_user, true );
  772.                                    
  773.                                 if (userpro_get_option('twitter_signin_redirect')){
  774.                                     wp_safe_redirect( userpro_get_option('twitter_signin_redirect') );
  775.                                 } elseif (userpro_get_option('after_login') == 'no_redirect') {
  776.                                     $redirect_uri =$_SESSION['current_page_uri'];
  777.                                     wp_safe_redirect( $redirect_uri );
  778.                                     exit;
  779.                                 }else{ 
  780.                                     wp_safe_redirect( $this->permalink() );
  781.                                 }
  782.                            
  783.                            
  784.                             }
  785.                            
  786.                             /* Fresh User */
  787.                             else {
  788.                                 $user_pass = wp_generate_password( $length=12, $include_standard_special_chars=false );
  789.                                 $unique_user = $this->unique_user('twitter', $user_info);
  790.                                
  791.                                 if(isset($user_info['email'])){
  792.                                     $user_id = $this->new_user( $unique_user, $user_pass, $user_info['email'], $user_info, $type='twitter' );
  793.                                 }
  794.                                 else
  795.                                     $user_id = $this->new_user( $unique_user, $user_pass, '', $user_info, $type='twitter' );
  796.                                
  797.                                 if (userpro_get_option('twitter_autopost') && userpro_get_option('twitter_autopost_msg') ) {
  798.                                     $this->twitter->post('statuses/update', array('status' => userpro_get_option('twitter_autopost_msg') ) );
  799.                                 }
  800.                                
  801.                                 userpro_auto_login( $unique_user, true );
  802.                             if (userpro_get_option('twitter_signin_redirect')){
  803.                                 wp_safe_redirect( userpro_get_option('twitter_signin_redirect') );
  804.                             } elseif (userpro_get_option('after_login') == 'no_redirect') {
  805.                                 $redirect_uri =$_SESSION['current_page_uri'];
  806.                                 wp_safe_redirect( $redirect_uri );
  807.                                 exit;
  808.                             }else{ 
  809.                                     wp_safe_redirect( $this->permalink() );
  810.                                 }
  811.                                
  812.                             }
  813.                        
  814.                     }
  815.                 }
  816.             }
  817.         }
  818.     }
  819.    
  820.     /******************************************
  821.     Get current page URL
  822.     ******************************************/
  823.     function get_current_page_url(){
  824.     global $post;
  825.         if ( is_front_page() ) :
  826.             $page_url = home_url();
  827.             else :
  828.             $page_url = 'http';
  829.         if ( isset( $_SERVER["HTTPS"] ) && $_SERVER["HTTPS"] == "on" )
  830.             $page_url .= "s";
  831.                 $page_url .= "://";
  832.                 if ( $_SERVER["SERVER_PORT"] != "80" )
  833.             $page_url .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
  834.                 else
  835.             $page_url .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
  836.             endif;
  837.            
  838.         return apply_filters( 'userpro_get_current_page_url', esc_url( $page_url ) );
  839.     }
  840.    
  841. function linkedin_authorize(){
  842.         if(isset($_REQUEST['wplUsername']) && (isset( $_REQUEST['_wpnonce']) && wp_verify_nonce($_REQUEST['_wpnonce'] , 'linkedin_auth'))){
  843.  
  844.             $username = $_REQUEST['wplUsername'];
  845.             $email= $_REQUEST['wplEmail'];
  846.             $displayName= $_REQUEST['wplDisplayName'];
  847.             $profileurl=$_REQUEST['wplProfilePic'];
  848.                
  849.             $user_id = username_exists( $username );
  850.                
  851.             if(!$user_id){
  852.                 $user_id=email_exists($email);
  853.                 if(!$user_id){
  854.                        
  855.                     $random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
  856.                     //$user_id= wp_create_user( , ,  );
  857.                     $user_id = $this->new_user( $displayName, $random_password, $email,$profileurl,$type='linkedin' );
  858.                    
  859.                 }
  860.             }
  861.                
  862.             $user_info = get_userdata($user_id);
  863.                
  864.             if ( !is_user_logged_in() ) {
  865.                 if(!get_user_meta( $user_id, 'userpro_account_status' , true)){
  866.                 wp_set_current_user( $user_id, $user_info->user_login );
  867.                 wp_set_auth_cookie( $user_id );
  868.                 add_action( 'userpro', array( $this, 'wplRedirectHomepage' ) );
  869.                 do_action( 'userpro', $user_info->user_login );
  870.                 }else{
  871.                 add_action('userpro_pre_form_message', 'userpro_msg_block_account');
  872.                 }
  873.             }
  874.         }
  875.     }
  876.    
  877.    
  878.     function instagram_authorize(){
  879.         if((isset($_REQUEST['wpInDisplayName']) || isset($_REQUEST['wpInUsername'])) && (isset( $_REQUEST['_wpnonce']) && wp_verify_nonce($_REQUEST['_wpnonce'] , 'instagram_auth'))){
  880.             $username = $_REQUEST['wpInDisplayName'];
  881.             $email= '';
  882.             $displayName= $_REQUEST['wpInUsername'];
  883.             $profilePic = $_REQUEST['wpInProfilePic'];
  884.            
  885.             $user_id = username_exists( $displayName );
  886.    
  887.             if(!$user_id){
  888.                     $random_password = wp_generate_password( $length=12, $include_standard_special_chars=false );
  889.                     $user_id = $this->new_user( $displayName, $random_password, $email,$profilePic,$type='instagram' );
  890.                    
  891.             }
  892.    
  893.             $user_info = get_userdata($user_id);
  894.    
  895.             if ( !is_user_logged_in() ) {
  896.             if(!get_user_meta( $user_id, 'userpro_account_status' , true)){
  897.                 wp_set_current_user( $user_id, $user_info->user_login );
  898.                 wp_set_auth_cookie( $user_id );
  899.                 add_action( 'userpro', array( $this, 'wpinRedirectHomepage' ) );
  900.                 do_action( 'userpro', $user_info->user_login );
  901.             }else{
  902.                 add_action('userpro_pre_form_message', 'userpro_msg_block_account');
  903.             }
  904.             }
  905.         }
  906.     }
  907.  
  908.     public function wplRedirectHomepage(){
  909.         global $userpro;
  910.         //Added by Niranjan for custom redirect.
  911.         $rules = get_option('userpro_redirects_login');
  912.         $redirect_uri = $userpro->permalink();
  913.        
  914.         if (userpro_get_option('after_login') == 'no_redirect'){
  915.             $redirect_uri =$_SESSION['current_page_uri'];
  916.         }
  917.        
  918.         if(isset($rules)){
  919.             $redirect_uri = apply_filters('userpro_login_redirect', $userpro->permalink());
  920.         }
  921.         echo "<script type='text/javascript'>
  922.                     window.location.href ='".$redirect_uri."'
  923.                   </script>";
  924.     }
  925.  
  926.     public function wpinRedirectHomepage(){
  927.         global $userpro;
  928.         //Added by Niranjan for custom redirect.
  929.         $rules =get_option('userpro_redirects_login');
  930.         $redirect_uri = $userpro->permalink();
  931.        
  932.         if (userpro_get_option('after_login') == 'no_redirect'){
  933.             $redirect_uri =$_SESSION['current_page_uri'];
  934.         }
  935.        
  936.         if(isset($rules))
  937.         {
  938.             $redirect_uri = apply_filters('userpro_login_redirect',$userpro->permalink());
  939.         }
  940.         echo "<script type='text/javascript'>
  941.                     window.location.href ='".$redirect_uri."'
  942.                   </script>";
  943.     }
  944.  
  945.     /******************************************
  946.     Users allowed to publish automatically
  947.     ******************************************/
  948.     function instant_publish_roles(){
  949.         $instant_publish_roles = userpro_get_option('instant_publish_roles');
  950.         if ($instant_publish_roles) {
  951.             $instant_publish_roles = explode(',', $instant_publish_roles);
  952.         } else {
  953.             $instant_publish_roles = array();
  954.         }
  955.         return $instant_publish_roles;
  956.     }
  957.    
  958.     /******************************************
  959.     Find if a user role exists in array of roles
  960.     ******************************************/
  961.     function user_role_in_array($user_id, $array) {
  962.         if(isset($user_id)){
  963.             $user = get_userdata($user_id);
  964.                         if(!empty($user)){
  965.             $user_roles = $user->roles;
  966.             if (isset($user_roles) && is_array($user_roles)){
  967.                 foreach($user_roles as $k => $v){
  968.                     if ( in_array($v, $array))
  969.                         return true;
  970.                 }
  971.             }
  972.                         }
  973.         }
  974.         return false;
  975.     }
  976.    
  977.     /******************************************
  978.     Multiple Registration Forms Support
  979.     ******************************************/
  980.     function multi_type_exists($type){
  981.         $multi = userpro_mu_get_option('multi_forms');
  982.         if (isset($multi[$type]))
  983.             return true;
  984.         return false;
  985.     }
  986.    
  987.     function multi_type_get_array($type){
  988.         $multi = userpro_mu_get_option('multi_forms');
  989.         return $multi[$type];
  990.     }
  991.    
  992.     /******************************************
  993.     Add query var
  994.     ******************************************/
  995.     public function add_query_var_vars() {
  996.         global $wp;
  997.         $wp->add_query_var('userpro_export_options');
  998.         $wp->add_query_var('userpro_export_fields');
  999.         $wp->add_query_var('userpro_export_groups');
  1000.     }
  1001.  
  1002.     /******************************************
  1003.     Redirect to download file
  1004.     ******************************************/
  1005.     public function admin_redirect_download_files(){
  1006.         global $wp;
  1007.         global $wp_query;
  1008.         //download export
  1009.         if (array_key_exists('userpro_export_options', $wp->query_vars) && $wp->query_vars['userpro_export_options'] == 'safe_download'){
  1010.             $this->download_file('userpro_export_options');
  1011.             die();
  1012.         }
  1013.         if (array_key_exists('userpro_export_fields', $wp->query_vars) && $wp->query_vars['userpro_export_fields'] == 'safe_download'){
  1014.             $this->download_file('userpro_export_fields');
  1015.             die();
  1016.         }
  1017.         if (array_key_exists('userpro_export_groups', $wp->query_vars) && $wp->query_vars['userpro_export_groups'] == 'safe_download'){
  1018.             $this->download_file('userpro_export_groups');
  1019.             die();
  1020.         }
  1021.     }
  1022.    
  1023.     /******************************************
  1024.     Download file to browser
  1025.     ******************************************/
  1026.     public function download_file($setting, $content = null, $file_name = null){
  1027.         if (! wp_verify_nonce($_REQUEST['nonce'], $setting) )
  1028.             die();
  1029.  
  1030.         //here you get the options to export and set it as content, ex:
  1031.         if ($setting == 'userpro_export_options') {
  1032.             $obj= get_option('userpro');
  1033.         }
  1034.         if ($setting == 'userpro_export_fields') {
  1035.             $obj= get_option('userpro_fields');
  1036.         }
  1037.         if ($setting == 'userpro_export_groups') {
  1038.             $obj= get_option('userpro_fields_groups');
  1039.         }
  1040.         $content = base64_encode(serialize($obj));
  1041.         $file_name = 'userpro_'. current_time('timestamp') .'.txt';
  1042.         header('HTTP/1.1 200 OK');
  1043.  
  1044.         if ( !current_user_can('manage_options') )
  1045.             die();
  1046.         if ($content === null || $file_name === null)
  1047.             die();
  1048.  
  1049.         $fsize = strlen($content);
  1050.         header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1051.         header('Content-Description: File Transfer');
  1052.         header("Content-Disposition: attachment; filename=" . $file_name);
  1053.         header("Content-Length: ".$fsize);
  1054.         header("Expires: 0");
  1055.         header("Pragma: public");
  1056.         echo $content;
  1057.         exit;
  1058.     }
  1059.    
  1060.     /******************************************
  1061.     Demo
  1062.     ******************************************/
  1063.     function trial_version(){
  1064.         if (get_option('userpro_activated') == 0){
  1065.             update_option('userpro_trial', 1);
  1066.         }
  1067.     }
  1068.    
  1069.     /******************************************
  1070.     validate license
  1071.     ******************************************/
  1072.     function validate_license($code){
  1073.         update_option('userpro_trial', 0);
  1074.         update_option('userpro_activated', 1);
  1075.         userpro_set_option('userpro_code', $code);
  1076.     }
  1077.    
  1078.     /******************************************
  1079.     invalidate license
  1080.     ******************************************/
  1081.     function invalidate_license($code){
  1082.         update_option('userpro_trial', 1);
  1083.         delete_option('userpro_activated');
  1084.         userpro_set_option('userpro_code', $code);
  1085.     }
  1086.  
  1087.     /******************************************
  1088.     Update facebook ID
  1089.     ******************************************/
  1090.     function update_fb_id($user_id, $id){
  1091.         // only for connected users - after login
  1092.         if (userpro_is_logged_in() && ( get_current_user_id() == $user_id ) ){
  1093.             update_user_meta($user_id, 'userpro_facebook_id', $id);
  1094.         }
  1095.     }
  1096.    
  1097.     /******************************************
  1098.     Update twitter ID
  1099.     ******************************************/
  1100.     function update_twitter_id($user_id, $id){
  1101.         update_user_meta($user_id, 'twitter_oauth_id', $id);
  1102.     }
  1103.    
  1104.     /******************************************
  1105.     Update google ID
  1106.     ******************************************/
  1107.     function update_google_id($user_id, $id){
  1108.         update_user_meta($user_id, 'userpro_google_id', $id);
  1109.     }
  1110.    
  1111.     /******************************************
  1112.     Strip weird chars from value
  1113.     ******************************************/
  1114.     function remove_denied_chars($val, $field=null){
  1115.         $val = preg_replace('/(?=\P{Nd})\P{L} /u', '', $val);
  1116.         if ($field == 'display_name'){
  1117.            
  1118.             if (!userpro_get_option('allow_dash_display_name')){
  1119.                 $val = str_replace('-','',$val);
  1120.             }
  1121.         } else {
  1122.             $val = str_replace('-','',$val);
  1123.         }
  1124.         $val = str_replace('&','',$val);
  1125.         $val = str_replace('+','',$val);
  1126.         //$val = str_replace("'",'',$val);
  1127.         return $val;
  1128.     }
  1129.    
  1130.     /******************************************
  1131.     User ID is admin
  1132.     ******************************************/
  1133.     function is_admin($user_id) {
  1134.         $user = get_userdata($user_id);
  1135.         if($user!=false){
  1136.             if ( $user->user_level >= 10 ) {
  1137.                 return true;
  1138.             }
  1139.         }
  1140.         return false;
  1141.     }
  1142.    
  1143.     /******************************************
  1144.     User exists by ID
  1145.     ******************************************/
  1146.     function user_exists( $user_id ) {
  1147.         $aux = get_userdata( $user_id );
  1148.         if($aux==false){
  1149.             return false;
  1150.         }
  1151.         return true;
  1152.     }
  1153.    
  1154.     /******************************************
  1155.     Manual attachment from uploads
  1156.     ******************************************/
  1157.     function new_attachment($post_id, $filename){
  1158.         $wp_upload_dir = wp_upload_dir();
  1159.         rename( $this->upload_path . basename( $filename ), $this->upload_path_wp . basename( $filename ) );
  1160.         $filename = $this->upload_path_wp . basename( $filename );
  1161.         $wp_filetype = wp_check_filetype(basename($filename), null );
  1162.         $attachment = array(
  1163.             'guid' => $wp_upload_dir['url'] . '/' . basename( $filename ),
  1164.             'post_mime_type' => $wp_filetype['type'],
  1165.             'post_title' => preg_replace( '/\.[^.]+$/', '', basename( $filename ) ),
  1166.             'post_content' => '',
  1167.             'post_status' => 'inherit'
  1168.         );
  1169.                 set_post_thumbnail_size('','');
  1170.         $attach_id = wp_insert_attachment( $attachment, $filename, $post_id );
  1171.                 $imagesize = getimagesize( $filename );
  1172.         // you must first include the image.php file
  1173.         // for the function wp_generate_attachment_metadata() to work
  1174.         require_once( ABSPATH . 'wp-admin/includes/image.php' );
  1175.         $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
  1176.                
  1177.         wp_update_attachment_metadata( $attach_id, $attach_data );
  1178.                
  1179.         return $attach_id;
  1180.     }
  1181.    
  1182.     function set_thumbnail($post_id, $attach_id){
  1183.         set_post_thumbnail($post_id, $attach_id);
  1184.     }
  1185.  
  1186.     /******************************************
  1187.     Get skin URL
  1188.     ******************************************/
  1189.     function skin_url(){
  1190.         $skin = userpro_get_option('skin');
  1191.         if ( class_exists('userpro_sk_api') && is_dir( userpro_sk_path . 'skins/'.$skin ) ) {
  1192.             $skin_url = userpro_sk_url . 'skins/'.$skin.'/img/';
  1193.         } else {
  1194.             $skin_url = userpro_url . 'skins/'.$skin.'/img/';
  1195.         }
  1196.        
  1197.         if (locate_template('userpro/skins/'.$skin.'/style.css') ) {
  1198.             $skin_url = get_template_directory_uri() . '/userpro/skins/'.$skin.'/img/';
  1199.         }
  1200.        
  1201.         return $skin_url;
  1202.     }
  1203.    
  1204.     /******************************************
  1205.     First choice? translation compatibility
  1206.     ******************************************/
  1207.     function is_first_option($args, $key, $user_id){
  1208.         if (isset($this->groups[$args['template']]['default'][$key]['options'])){
  1209.             $opts = $this->groups[$args['template']]['default'][$key]['options'];
  1210.             $value = userpro_profile_data($key, $user_id);
  1211.             $search = array_search($value, $opts);
  1212.             if ($search == 1)
  1213.                 return true;
  1214.         }
  1215.         return false;
  1216.     }
  1217.     /******************************************
  1218.     Deletes an entire folder easily (uses path)
  1219.     ******************************************/
  1220.     function delete_folder($dir) {
  1221.         if (!file_exists($dir)) return true;
  1222.         if (!is_dir($dir)) return unlink($dir);
  1223.         foreach (scandir($dir) as $item) {
  1224.             if ($item == '.' || $item == '..') continue;
  1225.             if (!$this->delete_folder($dir.DIRECTORY_SEPARATOR.$item)) return false;
  1226.         }
  1227.         return rmdir($dir);
  1228.     }
  1229.     public function makeAweberSubscribeEntry($user_id){
  1230.         include(userpro_path .'lib/aweber_api/aweber_api.php');
  1231.         $email = userpro_profile_data('user_email', $user_id);
  1232.         $fname = userpro_profile_data('first_name', $user_id);
  1233.         $credentials=array();
  1234.         if(get_option('userpro_aweber_credentials')===false){
  1235.             $credentials = AWeberAPI::getDataFromAweberID(userpro_get_option('aweber_api'));
  1236.             if(!$credentials){
  1237.                 echo 'Incorrect aweber authorization code';
  1238.             }
  1239.             else {
  1240.                 update_option('userpro_aweber_credentials',$credentials);
  1241.             }
  1242.         }
  1243.         else {
  1244.             $credentials=get_option('userpro_aweber_credentials');
  1245.                
  1246.         }
  1247.         list($consumerKey, $consumerSecret, $accessKey, $accessSecret) = $credentials;
  1248.        
  1249.         $aweber = new AWeberAPI($consumerKey, $consumerSecret);
  1250.         $account = $aweber->getAccount($accessKey, $accessSecret);
  1251.         $account_id = $account->id;
  1252.         $mylists = $account->lists;
  1253.         $list_name_found = false;
  1254.        
  1255.       foreach ($mylists as $list) {
  1256.      if($list->id == userpro_get_option('aweber_listname')){
  1257.             $list_name_found = true;
  1258.             try {//Create a subscriber                
  1259.                 $params = array(
  1260.                     'email' => $email,
  1261.                     'name' => $fname,
  1262.                 );
  1263.                 $subscribers = $list->subscribers;
  1264.                 $new_subscriber = $subscribers->create($params);
  1265.                        }catch (Exception $exc) {
  1266.                
  1267.                
  1268.             }    
  1269.         }
  1270.     }
  1271.        
  1272.        
  1273.        
  1274.     }
  1275. /******************************************
  1276.      Find status of follower
  1277.     ******************************************/
  1278.     function followere_email_subscriber($user_id){
  1279.    
  1280.  
  1281.             $followers=get_user_meta( $user_id,'followers_email' );
  1282.            
  1283.         if ($followers[0]=="unsubscribed"){
  1284.            
  1285.                     return true;
  1286.                 }
  1287.            
  1288.        
  1289.         return false;
  1290.    
  1291.     }
  1292.    
  1293.     /******************************************
  1294.     Subscribe to MailChimp
  1295.     ******************************************/
  1296.     function mailchimp_subscribe($user_id, $list_id=null) {
  1297.    
  1298.         $email = userpro_profile_data('user_email', $user_id);
  1299.         $fname = userpro_profile_data('first_name', $user_id);
  1300.         $lname = userpro_profile_data('last_name', $user_id);
  1301.         $objMailChimp = new UserProMailChimp( userpro_get_option('mailchimp_api') );
  1302.         $objMailChimp->call('lists/subscribe', array(
  1303.                 'id'                => $list_id,
  1304.                 'email'             => array('email'=> $email),
  1305.                 'merge_vars'        => array('FNAME'=> $fname, 'LNAME'=> $lname),
  1306.                 'double_optin'      => false,
  1307.                 'update_existing'   => true,
  1308.                 'replace_interests' => false,
  1309.                 'send_welcome'      => false,
  1310.         ));
  1311.        
  1312.     }
  1313.    
  1314.     /******************************************
  1315.      Unsubscribe to MailChimp
  1316.     ******************************************/
  1317.     function listUnsubscribe($id, $email_address, $delete_member=false, $send_goodbye=true, $send_notify=true) {
  1318.  
  1319.         $objMailChimp = new UserProMailChimp( userpro_get_option('mailchimp_api') );
  1320.         $objMailChimp->call("lists/unsubscribe", array(
  1321.                 'id'                => $id,
  1322.                 'email'             => array('email'=> $email_address),
  1323.                 'delete_member'        => $delete_member,
  1324.                 'send_goodbye'   => $send_notify,
  1325.                 'send_notify' => $send_notify,
  1326.         ));
  1327.     }
  1328.    
  1329.    
  1330.     /******************************************
  1331.      Campaignmonitor integration
  1332.  
  1333.     ******************************************/
  1334.    
  1335.     public function makeCampaignmonitorEntry($user_id){
  1336.        
  1337.         $email = userpro_profile_data('user_email', $user_id);
  1338.         include(userpro_path.'lib/campaignmonitor/csrest_subscribers.php');
  1339.    
  1340.         $list_id=userpro_get_option('Campaignmonitor_listname');
  1341.        
  1342.         $auth_details=array('api_key' => userpro_get_option('Campaignmonitor_api'));
  1343.    
  1344.         $api=new CS_REST_Subscribers($list_id,$auth_details);
  1345.    
  1346.         $subscriber=array ('EmailAddress' => $email);
  1347.         $api->add($subscriber);
  1348.        
  1349.     }
  1350.     /******************************************
  1351.     Unubscribe from MailChimp
  1352.     ******************************************/
  1353.     function mailchimp_unsubscribe($user_id, $list_id=null) {
  1354.        
  1355.         $email = userpro_profile_data('user_email', $user_id);
  1356.        
  1357.         $MailChimp = new UserProMailChimp( userpro_get_option('mailchimp_api') );
  1358.         $MailChimp->call('lists/unsubscribe', array(
  1359.                 'id'                => $list_id,
  1360.                 'email'             => array('email'=> $email)
  1361.         ));
  1362.        
  1363.     }
  1364.    
  1365.     /******************************************
  1366.     Find status of subscriber
  1367.     ******************************************/
  1368.     function mailchimp_is_subscriber($user_id, $list_id=null){
  1369.    
  1370.         if(userpro_get_option('mailchimp_api')!=''){
  1371.         $email = userpro_profile_data('user_email', $user_id);
  1372.         $MailChimp = new UserProMailChimp( userpro_get_option('mailchimp_api') );
  1373.         $results = $MailChimp->call('helper/lists-for-email', array(
  1374.                 'email'             => array('email'=> $email)
  1375.         ));
  1376.        
  1377.         if (isset($results) && is_array($results)){
  1378.             foreach($results as $k=> $arr){
  1379.                 if (isset($arr['id']) && $arr['id'] == $list_id){
  1380.                     return true;
  1381.                 }
  1382.             }
  1383.         }
  1384.        
  1385.         }
  1386.         if(userpro_get_option('mailster_activate')!=''){
  1387.            
  1388.         if($user_id !=''){         
  1389.             global $wpdb;
  1390.             require_once MAILSTER_DIR_USERPRO.'/mailster.php';
  1391.             $mailster_subscribers =new MailsterSubscribers();
  1392.             $subscriber = $mailster_subscribers->get_status();
  1393.             $table = $wpdb->prefix.'mailster_subscribers';     
  1394.             $userdata = $wpdb->get_results($wpdb->prepare("SELECT * FROM $table where wp_id = %s",$user_id));
  1395.             if(!empty($userdata)){                 
  1396.             foreach ($userdata as $ud){
  1397.                 $status =$ud->status;
  1398.             }
  1399.                 if($status == 0 || $status ==1){
  1400.                 return true;}
  1401.                 }
  1402.             }
  1403.         }
  1404.         return false;
  1405.  
  1406.  
  1407.        
  1408.     }
  1409.    
  1410.     /******************************************
  1411.     Verify purchase codes @ Envato
  1412.     ******************************************/
  1413.     function verify_purchase($code, $api_key=null, $username=null, $item_id=null) {
  1414.         if (!$api_key) $api_key = userpro_get_option('envato_api');
  1415.         if (!$username) $username = userpro_get_option('envato_username');
  1416.         require_once userpro_path . '/lib/envato/Envato_marketplaces.php';
  1417.         $Envato = new Envato_marketplaces();
  1418.         $Envato->set_api_key( $api_key );
  1419.         $verify = $Envato->verify_purchase( $username , $code);
  1420.         if ($item_id != '') {
  1421.             if ( isset($verify->buyer) && $verify->item_id == $item_id )
  1422.                 return true;
  1423.             return false;
  1424.         } else {
  1425.             if ( isset($verify->buyer) )
  1426.                 return true;
  1427.             return false;
  1428.         }
  1429.     }
  1430.    
  1431.     /******************************************
  1432.     Make envato verified
  1433.     ******************************************/
  1434.     function do_envato($user_id){
  1435.         update_user_meta($user_id, '_envato_verified', 1);
  1436.     }
  1437.    
  1438.     /******************************************
  1439.     Undo envato verified
  1440.     ******************************************/
  1441.     function undo_envato($user_id){
  1442.  
  1443.         update_user_meta($user_id, '_envato_verified', 0);
  1444.     }
  1445.    
  1446.     /******************************************
  1447.     Is Envato customer
  1448.     ******************************************/
  1449.     function is_envato_customer($user_id){
  1450.         $envato = get_user_meta($user_id, '_envato_verified', true);
  1451.         if ($envato == 1)
  1452.             return true;
  1453.         return false;
  1454.     }
  1455.    
  1456.     /******************************************
  1457.     Unique display names
  1458.     ******************************************/
  1459.     function display_name_exists($display_name) {
  1460.         $users = get_users(array(
  1461.             'meta_key'     => 'display_name',
  1462.             'meta_value'   => $display_name,
  1463.             'meta_compare' => '='
  1464.         ));
  1465.         if ( isset($users[0]->ID) && ( $users[0]->ID == get_current_user_id()) ) {
  1466.             return false;
  1467.         } elseif ( (isset($users[0]->ID) && current_user_can('manage_options'))||userpro_get_edit_userrole()  ) {
  1468.             return false;
  1469.         }
  1470.              elseif ( isset($users[0]->ID) && userpro_get_edit_userrole()) {
  1471.             return false;
  1472.         }
  1473.         elseif ( isset($users[0]->ID) ) {
  1474.             return true;
  1475.         }
  1476.         return false;
  1477.     }
  1478.    
  1479.     /******************************************
  1480.     Get valid file URI
  1481.     ******************************************/
  1482.     function file_uri($url, $user_id=false) {
  1483.  
  1484.         // external - needs no editing
  1485.         $method = userpro_get_option('picture_save_method');
  1486.         if ($method == 'external' && substr( $url, 0, 4 ) === "http" && strstr($url, 'fb') ){
  1487.             return $url;
  1488.         }
  1489.        
  1490.         $url = $this->get_uploads_url($user_id) . basename($url);
  1491.        
  1492.         if (userpro_get_option('use_relative') == 'relative') {
  1493.             if ( strstr($url, 'wp-content')) {
  1494.                 $url = explode('wp-content', $url);
  1495.                 $url = $url[1];
  1496.                
  1497.                 if ( userpro_get_option('ppfix') == 'b' ) {
  1498.                 $url = '' . $url;
  1499.                 } else {
  1500.                 $url = '/wp-content' . $url;
  1501.                 }
  1502.                
  1503.             }
  1504.         }
  1505.        
  1506.         return $url;
  1507.     }
  1508.    
  1509.     /******************************************
  1510.     Space in url correction
  1511.     ******************************************/
  1512.     function correct_space_in_url($url) {
  1513.         $url = str_replace(' ','%20',$url);
  1514.         return $url;
  1515.     }
  1516.    
  1517.     /******************************************
  1518.     Quickly update a field
  1519.     ******************************************/
  1520.     function update_field($field, $form) {
  1521.         $fields = $this->fields;
  1522.         $groups = $this->groups;
  1523.         foreach($form as $key => $value){
  1524.             if ($key != 'options'){
  1525.                 $fields[$field][$key] = $value;
  1526.                 foreach($groups as $group => $array){
  1527.                     if (isset( $groups[$group]['default'][$field]  ) ) {
  1528.                         $groups[$group]['default'][$field][$key] = $value;
  1529.                     }
  1530.                 }
  1531.             } else {
  1532.                 $encoding=mb_detect_encoding($value,'auto');
  1533.                 if($encoding!='ASCII' && $encoding!='UTF-8')
  1534.                 {
  1535.                     $value=mb_convert_encoding($value,'UTF-8','auto');
  1536.                 }
  1537.                 $fields[$field][$key] = preg_split('/[\r\n]+/', $value, -1, PREG_SPLIT_NO_EMPTY);
  1538.                 foreach($groups as $group => $array){
  1539.                     if (isset( $groups[$group]['default'][$field]  ) ) {
  1540.                         $groups[$group]['default'][$field][$key] = preg_split('/[\r\n]+/', $value, -1, PREG_SPLIT_NO_EMPTY);
  1541.                     }
  1542.                 }
  1543.             }
  1544.         }
  1545.         update_option('userpro_fields', $fields);
  1546.         update_option('userpro_fields_groups', $groups);
  1547.     }
  1548.    
  1549.     /******************************************
  1550.     Create new group
  1551.     ******************************************/
  1552.     function create_group($group) {
  1553.         $groups = $this->groups;
  1554.         $groups[$group]['default'] = '';
  1555.         update_option('userpro_fields_groups',$groups);
  1556.     }
  1557.    
  1558.     /******************************************
  1559.     hidden fields from profile view
  1560.     ******************************************/
  1561.     function fields_to_hide_from_view(){
  1562.         $option = userpro_get_option('hidden_from_view');
  1563.         $arr = explode(',',$option);
  1564.         return $arr;
  1565.     }
  1566.    
  1567.     /******************************************
  1568.     Posts by user
  1569.     ******************************************/
  1570.     function posts_by_user($user_id, $opts) {
  1571.        if ( strstr( $opts['postsbyuser_types'], ',') ) {
  1572.             $post_types = explode(',', $opts['postsbyuser_types']);
  1573.         } else {
  1574.             $post_types = $opts['postsbyuser_types'];
  1575.         }
  1576.  
  1577.         if (!isset($opts['all_users'])) {
  1578.  
  1579.             $args['author'] = $user_id;
  1580.        
  1581.         }
  1582.         $args['posts_per_page'] = $opts['postsbyuser_num'];
  1583.         $offset = (isset($_GET['postp'])) ? ($_GET['postp']-1)*$args['posts_per_page'] : 0;
  1584.         $args['offset'] = $offset;
  1585.         $args['post_type'] = $post_types;
  1586.        
  1587.         /* Show posts from specific category */
  1588.         if (isset($opts['postsbyuser_category']) && !empty($opts['postsbyuser_category']) ){
  1589.             $args['tax_query'] = array(
  1590.                 array(
  1591.                     'taxonomy' => $opts['postsbyuser_taxonomy'],
  1592.                     'field' => 'term_id',
  1593.                     'terms' => explode(',',$opts['postsbyuser_category'])
  1594.                 )
  1595.             );
  1596.         }
  1597.  
  1598.         $post_query = new WP_Query( $args );
  1599.        
  1600.         return $post_query;
  1601.     }
  1602.    
  1603.     /******************************************
  1604.     Get first image in a post
  1605.     ******************************************/
  1606.     function get_first_image($postid) {
  1607.         $post = get_post($postid);
  1608.         setup_postdata($post);
  1609.         $first_img = '';
  1610.         ob_start();
  1611.         ob_end_clean();
  1612.                 $output = array();
  1613.         $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
  1614.         if (isset( $matches[1][0])) {
  1615.             $first_img = $matches[1][0];
  1616.         }
  1617.         if(isset($first_img) && !empty($first_img)) {
  1618.             return $first_img;
  1619.         }
  1620.     }
  1621.    
  1622.     /******************************************
  1623.     Get thumbnail URL based on post ID
  1624.     ******************************************/
  1625.     function post_thumb_url( $postid ) {
  1626.         $encoded = '';
  1627.         if (get_post_thumbnail_id( $postid ) != '') {
  1628.             $image = wp_get_attachment_image_src( get_post_thumbnail_id( $postid ), 'large' );
  1629.             $encoded = urlencode($image[0]);
  1630.         } elseif ( $this->get_first_image($postid) != '' ) {
  1631.             $encoded = urlencode( $this->get_first_image($postid) );
  1632.         } else {
  1633.             $encoded = urlencode ( userpro_url . 'img/placeholder.jpg' );
  1634.         }
  1635.         return $encoded;
  1636.     }
  1637.    
  1638.     /******************************************
  1639.     Get post thumbnail image (size wise)
  1640.     ******************************************/
  1641.     function post_thumb( $postid, $size=400 ) {
  1642.         require_once(userpro_path.'lib/BFI_Thumb.php');
  1643.         $post_thumb_url = $this->post_thumb_url( $postid );
  1644.         if (isset($post_thumb_url)) {
  1645.             $params = array('width'=>$size,'height'=>$size,'quality'=>100);
  1646.             $cropped_thumb = bfi_thumb(urldecode($post_thumb_url),$params);
  1647.             $img = '<img src="'.$cropped_thumb.'" alt="" />';
  1648.             return $img;
  1649.         }
  1650.     }
  1651.    
  1652.     /******************************************
  1653.     Count found results
  1654.     ******************************************/
  1655.     function found_members($count){
  1656.         if ($count == 1){
  1657.             return __('Found <span>1</span> Member','userpro');
  1658.         } else {
  1659.             return sprintf(__('Found <span>%s</span> Members','userpro'), $count);
  1660.         }
  1661.     }
  1662.    
  1663.     /******************************************
  1664.     Get online users
  1665.     ******************************************/
  1666.     function onlineusers(){
  1667.         $online = get_transient('userpro_users_online');
  1668.         $include = array();
  1669.         if (is_array($online)) {
  1670.            
  1671.             foreach($online as $k=>$t){
  1672.                 $include[] = $k;
  1673.             }
  1674.             if(!empty($include)){
  1675.                 $query['include'] = $include;
  1676.            
  1677.             $wp_user_query = $this->get_cached_query( $query );
  1678.             if (! empty( $wp_user_query->results )) {
  1679.                 return $wp_user_query->results;
  1680.             }
  1681.             }
  1682.         }
  1683.     }
  1684.    
  1685.     /******************************************
  1686.     Is user online
  1687.     ******************************************/
  1688.     function is_user_online($user_id) {
  1689.         $online = get_transient('userpro_users_online');
  1690.         if (isset($online) && is_array($online) && isset($online[$user_id]) )
  1691.             return true;
  1692.         return false;
  1693.     }
  1694.  
  1695.     /******************************************
  1696.     Update online users
  1697.     ******************************************/
  1698.     function update_online_users(){
  1699.       if(is_user_logged_in()){
  1700.  
  1701.         if (userpro_get_option('hide_online_admin') && userpro_is_admin( get_current_user_id() ) ) return;
  1702.        
  1703.         if(($logged_in_users = get_transient('userpro_users_online')) === false) $logged_in_users = array();
  1704.  
  1705.         $current_user = wp_get_current_user();
  1706.         $current_user = $current_user->ID;  
  1707.         $current_time = current_time('timestamp');
  1708.  
  1709.         if(!isset($logged_in_users[$current_user]) || ($logged_in_users[$current_user] < ($current_time - (15 * 60) ))){
  1710.           $logged_in_users[$current_user] = $current_time;
  1711.           set_transient('userpro_users_online', $logged_in_users, (30 * 60) );
  1712.         }
  1713.  
  1714.       }
  1715.     }
  1716.    
  1717.     /******************************************
  1718.     Create special class for online user
  1719.     ******************************************/
  1720.     function online_user_special($user_id){
  1721.         if (userpro_is_admin($user_id)){
  1722.             return 'admin';
  1723.         }
  1724.     }
  1725.    
  1726.     /******************************************
  1727.     Prepares a user for pending email verify
  1728.     ******************************************/
  1729.     function process_email_approve(){
  1730.         if (isset($_GET['act']) && isset($_GET['user_id']) && isset($_GET['user_verification_key'])) {
  1731.             if ($_GET['act'] == 'verify_account' && (int)$_GET['user_id'] && strlen($_GET['user_verification_key']) == 20) {
  1732.                
  1733.                 // valid request, try to validate user
  1734.                 if ( $this->is_pending($_GET['user_id']) ){
  1735.                     $salt_check = get_user_meta($_GET['user_id'], '_account_verify', true);
  1736.                     if ($salt_check == $_GET['user_verification_key']) {
  1737.                         $this->activate( $_GET['user_id'] );
  1738.                         wp_safe_redirect( add_query_arg('accountconfirmed', 'true', esc_url($this->permalink()) ) );
  1739.                         exit;
  1740.                     }
  1741.                 }
  1742.                
  1743.             }
  1744.         }
  1745.        
  1746.         if (isset($_GET['accountconfirmed']) && $_GET['accountconfirmed'] == 'true') {
  1747.             add_action('userpro_pre_form_message', 'userpro_msg_account_validated', 999);
  1748.         }
  1749.     }
  1750.    
  1751.     /******************************************
  1752.     Process verification invite
  1753.     ******************************************/
  1754.     function process_verification_invites(){
  1755.         if (isset($_GET['act']) && isset($_GET['user_id']) && isset($_GET['hash_secret'])) {
  1756.             if ($_GET['act'] == 'verified_invitation' && (int)$_GET['user_id'] && strlen($_GET['hash_secret']) == 20) {
  1757.            
  1758.                 // valid request, verify user
  1759.                 $hash = get_user_meta($_GET['user_id'], '_invite_verify', true);
  1760.                 if ($hash == $_GET['hash_secret']) {
  1761.                     $this->verify( $_GET['user_id'] );
  1762.                     add_action('wp_footer', 'userpro_check_status_verified');
  1763.                 } else {
  1764.                 // invalid expired
  1765.                     add_action('wp_footer', 'userpro_failed_status_verified');
  1766.                 }
  1767.            
  1768.             }
  1769.         }
  1770.     }
  1771.  
  1772.     /******************************************
  1773.     Create a validation URL automatically
  1774.     ******************************************/
  1775.     function create_validate_url($user_id) {
  1776.         $salt = get_user_meta($user_id, '_account_verify', true);
  1777.         if ($salt && strlen($salt) == 20) {
  1778.             $url = home_url() . '/';
  1779.             $url = add_query_arg( 'act', 'verify_account', $url );
  1780.             $url = add_query_arg( 'user_id', $user_id, $url );
  1781.             $url = add_query_arg( 'user_verification_key', $salt, $url );
  1782.             return $url;
  1783.         }
  1784.     }
  1785.    
  1786.     /******************************************
  1787.     Prepares a user for pending email verify
  1788.     ******************************************/
  1789.     function pending_email_approve($user_id, $user_pass, $form) {
  1790.         $new_account_salt = wp_generate_password( $length=20, $include_standard_special_chars=false );
  1791.         update_user_meta($user_id, '_account_verify', $new_account_salt);
  1792.         update_user_meta($user_id, '_account_status', 'pending');
  1793.         update_user_meta($user_id, '_pending_pass', $user_pass);
  1794.         update_user_meta($user_id, '_pending_form', $form);
  1795.         userpro_mail($user_id, 'verifyemail', null, $form );
  1796.         if(userpro_get_option('notify_admin_email_approve')){
  1797.             userpro_mail($user_id, 'verifyemailadmin', null, $form );
  1798.         }  
  1799.     }
  1800.    
  1801.     /******************************************
  1802.     Prepares a user for pending admin verify
  1803.     ******************************************/
  1804.     function pending_admin_approve($user_id, $user_pass, $form) {
  1805.         $new_account_salt = wp_generate_password( $length=20, $include_standard_special_chars=false );
  1806.         update_user_meta($user_id, '_account_status', 'pending_admin');
  1807.         update_user_meta($user_id, '_pending_pass', $user_pass);
  1808.         update_user_meta($user_id, '_pending_form', $form);
  1809.         userpro_mail($user_id, 'pendingapprove', null, $form );
  1810.     }
  1811.    
  1812.     /******************************************
  1813.     Simply ensures a user is activated before
  1814.     allowing him to login, etc.
  1815.     ******************************************/
  1816.     function is_active($user_id) {
  1817.         $checkuser = get_user_meta($user_id, '_account_status', true);
  1818.         if ($checkuser == 'active')
  1819.             return true;
  1820.         return false;
  1821.     }
  1822.    
  1823.     /******************************************
  1824.     Check for a pending user
  1825.     ******************************************/
  1826.     function is_pending($user_id) {
  1827.         $checkuser = get_user_meta($user_id, '_account_status', true);
  1828.         if ($checkuser == 'pending' || $checkuser == 'pending_admin' || $checkuser == 'expired_subscription')
  1829.             return true;
  1830.         return false;
  1831.     }
  1832.    
  1833.     /******************************************
  1834.     Activate a user
  1835.     ******************************************/
  1836.     function activate($user_id, $user_login = null) {
  1837.         if ($user_login != ''){
  1838.             $user = get_user_by('login', $user_login);
  1839.             $user_id = $user->ID;
  1840.         }
  1841.        
  1842.         $result=get_user_meta($user_id,"userpayment");
  1843.         $uppayment=get_option('userpro_payment');
  1844.         if($uppayment['userpro_payment_option']=='y')
  1845.         {
  1846.         if(isset($result[0]) && $result[0]=="recive" || is_super_admin( get_current_user_id() ))
  1847.         {
  1848.            
  1849.         delete_user_meta($user_id, '_account_verify');
  1850.         update_user_meta($user_id, '_account_status', 'active');
  1851.        
  1852.         $password = get_user_meta($user_id, '_pending_pass', true);
  1853.         $form = get_user_meta($user_id, '_pending_form', true);
  1854.         userpro_mail($user_id, 'newaccount', $password, $form );
  1855.         do_action('userpro_after_new_registration', $user_id);
  1856.        
  1857.         delete_user_meta($user_id, '_pending_pass');
  1858.         delete_user_meta($user_id, '_pending_form');
  1859.         }
  1860.         }
  1861.         else
  1862.         {
  1863.            
  1864.         delete_user_meta($user_id, '_account_verify');
  1865.         update_user_meta($user_id, '_account_status', 'active');
  1866.        
  1867.         $password = get_user_meta($user_id, '_pending_pass', true);
  1868.         $form = get_user_meta($user_id, '_pending_form', true);
  1869.         userpro_mail($user_id, 'newaccount', $password, $form );
  1870.         do_action('userpro_after_new_registration', $user_id);
  1871.        
  1872.         delete_user_meta($user_id, '_pending_pass');
  1873.         delete_user_meta($user_id, '_pending_form');
  1874.            
  1875.         }
  1876.        
  1877.     }
  1878.    
  1879.     /******************************************
  1880.     Get a cached query
  1881.     ******************************************/
  1882.     function get_cached_query($query){
  1883.         $cached = $this->get_cached_results;
  1884.         $testcache = serialize($query);
  1885.         if ( !isset($cached["$testcache"]) ) {
  1886.             $cached["$testcache"] = new WP_User_Query( unserialize($testcache) );
  1887.             update_option('userpro_cached_results', $cached);
  1888.             $query = $cached["$testcache"];
  1889.         } else {
  1890.             $query = $cached["$testcache"];
  1891.         }
  1892.         return $query;
  1893.     }
  1894.  
  1895.     /******************************************
  1896.     Clear previous cache
  1897.     ******************************************/
  1898.     function clear_cache(){
  1899.         delete_option('userpro_cached_results');
  1900.     }
  1901.    
  1902.     /******************************************
  1903.     Extract user id/data of profile
  1904.     ******************************************/
  1905.     function try_user_id($args){
  1906.         if ($args['user'] == 'url' && get_query_var('up_username') ) {
  1907.             $user_id = $this->get_member_by_queryvar_from_id();
  1908.         } elseif ( $args['user'] != '' ) {
  1909.             $user = get_user_by('login', $args['user']);
  1910.             $user_id = $user->ID;
  1911.         } else {
  1912.             $user_id = get_current_user_id();
  1913.         }
  1914.         return $user_id;
  1915.     }
  1916.    
  1917.     /******************************************
  1918.     Content to fields
  1919.     ******************************************/
  1920.     function content_to_fields($content, $id=0) {
  1921.         $user_id = $this->get_member_by_queryvar_from_id();
  1922.         if ($id){
  1923.             $user_id = $id;
  1924.         }
  1925.         $user = get_userdata($user_id);
  1926.        
  1927.         foreach($this->fields as $key => $v){
  1928.             $merged_keys[] = $key;
  1929.         }
  1930.        
  1931.         $merged_keys = array_merge($merged_keys, array('username','role') );
  1932.        
  1933.         foreach($merged_keys as $key){
  1934.             switch($key){
  1935.                 case 'user_login':
  1936.                     $fields['[' . $key . ']'] = '<span class="up-'.$key.'">'.$user->user_login.'</span>';
  1937.                     break;
  1938.                 case 'role':
  1939.                     $fields['[' . $key . ']'] = '<span class="up-'.$key.'">'.$this->get_role_nice($user).'</span>';
  1940.                     break;
  1941.                 default:
  1942.                     $fields['[' . $key . ']'] = '<span class="up-'.$key.'">'.get_user_meta($user_id, $key, true).'</span>';
  1943.                     break;
  1944.             }
  1945.            
  1946.             if (strstr($key, 'profilepicture')) {
  1947.                 $fields['[' . $key . ']'] = '<span class="up-'.$key.'">'.get_avatar($user_id, 64).'</span>';
  1948.                 $fields['[' . $key .  ' round]'] = '<span class="up-'.$key.' up-round">'.get_avatar($user_id, 64).'</span>';
  1949.             }
  1950.         }
  1951.        
  1952.         $search = array_keys($fields);
  1953.         $replace = array_values($fields);
  1954.         $content = str_replace( $search, $replace, $content);
  1955.         return apply_filters('userpro_content_from_field_filter', $content, $user_id);
  1956.     }
  1957.    
  1958.     /******************************************
  1959.     If a field exists in builtin+custom fields
  1960.     ******************************************/
  1961.     function field_exists($key){
  1962.         if ( isset($this->fields[$key]) ){
  1963.             return true;
  1964.         }
  1965.         return false;
  1966.     }
  1967.    
  1968.     /******************************************
  1969.     Gets a field label
  1970.     ******************************************/
  1971.     function field_label($key){
  1972.         if ( isset($this->fields[$key]) && isset($this->fields[$key]['label'])){
  1973.             return $this->fields[$key]['label'];
  1974.         } else {
  1975.             return null;
  1976.         }
  1977.     }
  1978.    
  1979.     /******************************************
  1980.     Gets a field type
  1981.     ******************************************/
  1982.     function field_type($key){
  1983.         if ( isset($this->fields[$key]) && isset($this->fields[$key]['type'])){
  1984.             return $this->fields[$key]['type'];
  1985.         }
  1986.         return false;
  1987.     }
  1988.    
  1989.     /******************************************
  1990.     Gets a field icon
  1991.     ******************************************/
  1992.     function field_icon($key){
  1993.         if ( isset($this->fields[$key]) && isset($this->fields[$key]['icon'])){
  1994.             return $this->fields[$key]['icon'];
  1995.         }
  1996.     }
  1997.    
  1998.     /******************************************
  1999.     Update field icons
  2000.     ******************************************/
  2001.     function update_field_icons() {
  2002.         $fields = $this->fields;
  2003.         if (isset($fields) && is_array($fields) && get_option('userpro_fields') ){
  2004.         foreach($fields as $field => $arr){
  2005.             switch($field){
  2006.                
  2007.                 default: $fields[$field]['icon'] = ''; break;
  2008.                 case 'country': $fields['country']['icon'] = 'map-marker'; break;
  2009.                 case 'user_email':  $fields['user_email']['icon'] = 'envelope-alt'; break;
  2010.                 case 'user_login':  $fields['user_login']['icon'] = 'user'; break;
  2011.                 case 'username_or_email':  $fields['username_or_email']['icon'] = 'user'; break;
  2012.                 case 'user_pass':  $fields['user_pass']['icon'] = 'lock'; break;
  2013.                 case 'facebook':  $fields['facebook']['icon'] = 'facebook'; break;
  2014.                 case 'twitter':  $fields['twitter']['icon'] = 'twitter'; break;
  2015.                 case 'google_plus':  $fields['google_plus']['icon'] = 'google-plus'; break;
  2016.                 case 'profilepicture':  $fields['profilepicture']['icon'] = 'camera'; break;
  2017.                 case 'user_url':  $fields['user_url']['icon'] = 'home'; break;
  2018.                 case 'linkedin':  $fields['linkedin']['icon'] = 'linkedin'; break;
  2019.                 case 'instagram':  $fields['instagram']['icon'] = 'instagram'; break;
  2020.                 case 'youtube':  $fields['youtube']['icon'] = 'youtube'; break;
  2021.             }
  2022.            
  2023.         }
  2024.         update_option('userpro_fields', $fields);
  2025.         update_option('userpro_pre_icons_setup',1);
  2026.         }
  2027.     }
  2028.    
  2029.     /******************************************
  2030.     If admin is checking notices
  2031.     ******************************************/
  2032.     function admin_user_notice($user_id){
  2033.         if (userpro_get_option('admin_user_notices') && current_user_can('manage_options') )
  2034.             return true;
  2035.         return false;
  2036.     }
  2037.    
  2038.     /******************************************
  2039.     Show user notices
  2040.     ******************************************/
  2041.     function user_notice_viewable( $user_id ){
  2042.         if (userpro_get_option('show_user_notices') || ( $user_id == get_current_user_id() ) )
  2043.             return true;
  2044.     }
  2045.    
  2046.     /******************************************
  2047.     Has usermeta
  2048.     ******************************************/
  2049.     function has($field, $user_id){
  2050.         $meta = get_user_meta($user_id, $field, true);
  2051.         if ($meta != '')
  2052.             return true;
  2053.         return false;
  2054.     }
  2055.    
  2056.     /******************************************
  2057.     Get usermeta
  2058.     ******************************************/
  2059.     function get($field, $user_id){
  2060.         return get_user_meta($user_id, $field, true);
  2061.     }
  2062.    
  2063.     /******************************************
  2064.     Set usermeta
  2065.     ******************************************/
  2066.     function set($field, $value, $user_id){
  2067.         if ($user_id != get_current_user_id() && !current_user_can('manage_options') )
  2068.             die();
  2069.         update_user_meta($user_id, $field, esc_attr($value) );
  2070.     }
  2071.    
  2072.     /******************************************
  2073.     Create uploads dir if does not exist
  2074.     ******************************************/
  2075.     function do_uploads_dir($user_id=0) {
  2076.    
  2077.         if (!file_exists( $this->upload_base_dir . '.htaccess') ) {
  2078.  
  2079. $data = <<<EOF
  2080. <Files ~ "\.txt$">
  2081. Order allow,deny
  2082. Deny from all
  2083. </Files>
  2084. EOF;
  2085.  
  2086.             file_put_contents( $this->upload_base_dir . '.htaccess' , $data);
  2087.         }
  2088.    
  2089.         if (!file_exists( $this->upload_base_dir )) {
  2090.             @mkdir( $this->upload_base_dir, 0777, true);
  2091.         }
  2092.        
  2093.         if ($user_id > 0) { // upload dir for a user
  2094.             if (!file_exists( $this->upload_base_dir . $user_id . '/' )) {
  2095.                 @mkdir( $this->upload_base_dir . $user_id . '/', 0777, true);
  2096.             }
  2097.         }
  2098.     }
  2099.    
  2100.     /******************************************
  2101.     Get the proper uploads dir
  2102.     ******************************************/
  2103.     function get_uploads_dir($user_id=0){
  2104.         if ($user_id > 0) {
  2105.             return $this->upload_base_dir . $user_id . '/';
  2106.         }
  2107.         return $this->upload_base_dir;
  2108.     }
  2109.    
  2110.     /******************************************
  2111.     Return the uploads URL
  2112.     ******************************************/
  2113.     function get_uploads_url($user_id=0){
  2114.         if ($user_id > 0) {
  2115.             return $this->upload_base_url . $user_id . '/';
  2116.         }
  2117.         return $this->upload_base_url;
  2118.     }
  2119.    
  2120.     /******************************************
  2121.     Show social bar icons
  2122.     ******************************************/
  2123.     function show_social_bar( $args, $user_id, $wrapper=null) {
  2124.         if ($args['show_social'] == 1){
  2125.             userpro_profile_icons( $args, $user_id, $wrapper );
  2126.         }
  2127.     }
  2128.    
  2129.     /******************************************
  2130.     Integrate social bar without args
  2131.     ******************************************/
  2132.     function show_social_bar_clean( $user_id, $wrapper=null) {
  2133.         userpro_profile_icons_noargs(  $user_id, $wrapper );
  2134.     }
  2135.    
  2136.     /******************************************
  2137.     Can reset admin password or not
  2138.     ******************************************/
  2139.     function can_reset_pass( $username ){
  2140.         if ( userpro_is_admin( username_exists($username) ) && userpro_get_option('reset_admin_pass') == 0 )
  2141.             return false;
  2142.         return true;
  2143.     }
  2144.    
  2145.     /******************************************
  2146.     from ID to member arg
  2147.     ******************************************/
  2148.     function id_to_member( $user_id ) {
  2149.         $res = '';
  2150.         $nice_url = userpro_get_option('permalink_type');
  2151.         $user = get_userdata( $user_id );
  2152.         if ($nice_url == 'ID') $res = $user_id;
  2153.         if ($nice_url == 'username') $res = $user->user_login;
  2154.         if ($nice_url == 'name') {
  2155.             $res = $this->get_fullname_by_userid( $user_id );
  2156.         }
  2157.         if ($nice_url == 'display_name'){
  2158.             $res = userpro_profile_data('display_name', $user_id);
  2159.         }
  2160.         if ($res != '')
  2161.             return $res;
  2162.     }
  2163.    
  2164.     /******************************************
  2165.     Get full name of user by ID
  2166.     ******************************************/
  2167.     function get_fullname_by_userid( $user_id ) {
  2168.         $first_name = get_user_meta($user_id, 'first_name', true);
  2169.         $last_name = get_user_meta($user_id, 'last_name', true);
  2170.         $first_name = str_replace(' ', '_', $first_name);
  2171.         $last_name = str_replace(' ', '_', $last_name);
  2172.         $name = $first_name . '-' . $last_name;
  2173.         return $name;
  2174.     }
  2175.    
  2176.     /******************************************
  2177.     Get full name (user friendly)
  2178.     ******************************************/
  2179.     function get_full_name( $user_id ) {
  2180.         $first_name = get_user_meta($user_id, 'first_name', true);
  2181.         $last_name = get_user_meta($user_id, 'last_name', true);
  2182.         $name = $first_name . ' ' . $last_name;
  2183.         return $name;
  2184.     }
  2185.    
  2186.     /******************************************
  2187.     Get user ID only by query var
  2188.     ******************************************/
  2189.     function get_member_by_queryvar_from_id(){
  2190.         $arg = get_query_var('up_username');
  2191.         if ( $arg ) {
  2192.             $user = $this->get_member_by( $arg );
  2193.             return $user->ID;
  2194.         }
  2195.     }
  2196.    
  2197.     /******************************************
  2198.     Check that page exists
  2199.     ******************************************/
  2200.     function page_exists($id){
  2201.         $page_data = get_page($id);
  2202.         if (isset($page_data->post_status)){
  2203.         if($page_data->post_status == 'publish'){
  2204.             return true;
  2205.         }
  2206.         }
  2207.         return false;
  2208.     }
  2209.    
  2210.     /******************************************
  2211.     Get permalink for user
  2212.     ******************************************/
  2213.     function permalink( $user_id=0, $request='profile', $option='userpro_pages' ) {
  2214.         $pages = get_option( $option );
  2215.        
  2216.         if (isset($pages[$request]) && $this->page_exists($pages[$request]) ){
  2217.             $page_id = $pages[ $request ];
  2218.         } else {
  2219.             $default = get_option('userpro_pages');
  2220.             $page_id = $default['profile'];
  2221.         }
  2222.        
  2223.         if ($user_id > 0) {
  2224.        
  2225.             $user = get_userdata( $user_id );
  2226.             $nice_url = userpro_get_option('permalink_type');
  2227.             if ($nice_url == 'ID') {
  2228.                 $clean_user_login = $user_id;
  2229.                
  2230.             }
  2231.             if ($nice_url == 'username') {
  2232.                 $clean_user_login = $user->user_login;
  2233.                
  2234.                 $clean_user_login = str_replace(' ','-',$clean_user_login);
  2235.                
  2236.             }
  2237.             if ($nice_url == 'name'){
  2238.                 $clean_user_login = $this->get_fullname_by_userid( $user_id );
  2239.             }
  2240.             if ($nice_url == 'display_name'){
  2241.                 $clean_user_login = userpro_profile_data('display_name', $user_id);
  2242.                 $clean_user_login = str_replace(' ','-',$clean_user_login);
  2243.                 $clean_user_login = urlencode($clean_user_login);
  2244.             }
  2245.  
  2246.             /* append permalink */
  2247.             if ( get_option('permalink_structure') == '' ) {
  2248.                 $link = add_query_arg( 'up_username', $clean_user_login, esc_url(get_page_link($page_id)) );
  2249.             } else {
  2250.                 $link = trailingslashit ( trailingslashit( get_page_link($page_id) ) . $clean_user_login );
  2251.             }
  2252.        
  2253.         } else {
  2254.             $link = get_page_link($page_id);
  2255.         }
  2256.        
  2257.         if ($request == 'view' || $request == 'profile') {
  2258.             $link = apply_filters('userpro_user_profile_url', $link, $user_id);
  2259.         }
  2260.  
  2261.         return $link;
  2262.     }
  2263.    
  2264.     /******************************************
  2265.     Display name by arg
  2266.     ******************************************/
  2267.     function display_name_by_arg( $arg) {
  2268.         $user = $this->get_member_by($arg);
  2269.         return userpro_profile_data('display_name', $user->ID);
  2270.     }
  2271.    
  2272.     /******************************************
  2273.     Get clean member user from arg
  2274.     ******************************************/
  2275.     function get_member_by( $arg, $force=0 ) {
  2276.         if ($force) {
  2277.        
  2278.             $user = get_user_by('login', $arg);
  2279.            
  2280.         } elseif ($arg) {
  2281.        
  2282.             $nice_url = userpro_get_option('permalink_type');
  2283.             if ($nice_url == 'ID') {
  2284.                 $user = get_userdata( $arg );
  2285.             }
  2286.            
  2287.             if ($nice_url == 'username') {
  2288.                 $arg = str_replace('-',' ', $arg);
  2289.                     $user = get_user_by('login', $arg);
  2290.                 if( !$user)
  2291.                 {
  2292.                     $arg = str_replace(' ','-',$arg);
  2293.                     $user = get_user_by('login', $arg);
  2294.                 }
  2295.                 $user = get_user_by('login', $arg);
  2296.             }
  2297.            
  2298.             if ($nice_url == 'display_name'){
  2299.  
  2300.                
  2301.                 $arg = str_replace('-',' ', $arg);
  2302.                 $arg = urldecode($arg);
  2303.                 $args['meta_query'][] = array(
  2304.                     'key' => 'display_name',
  2305.                     'value' => $arg,
  2306.                     'compare' => '='
  2307.                 );
  2308.                 $getUser = new WP_User_Query( $args );
  2309.                 if ( isset($getUser->results) && isset($getUser->results[0]) ){
  2310.                     $user = $getUser->results[0];
  2311.                 } else {
  2312.                     $user = get_user_by('login', $arg);
  2313.                 }
  2314.             }
  2315.            
  2316.             if ($nice_url == 'name'){
  2317.                 $name = explode('-', $arg);
  2318.                
  2319.                 $first_name = $name[0];
  2320.                 $last_name = $name[1];
  2321.                
  2322.                 $first_name = urldecode($first_name);
  2323.                 $last_name = urldecode($last_name);
  2324.                
  2325.                 $first_name = str_replace('_',' ', $first_name);
  2326.                 $last_name = str_replace('_',' ', $last_name);
  2327.                
  2328.                 $args['meta_query'][] = array(
  2329.                     'key' => 'first_name',
  2330.                     'value' => $first_name,
  2331.                     'compare' => '='
  2332.                 );
  2333.                 $args['meta_query'][] = array(
  2334.                     'key' => 'last_name',
  2335.                     'value' => $last_name,
  2336.                     'compare' => '='
  2337.                 );
  2338.                 $getUser = new WP_User_Query( $args );
  2339.                 if ( isset($getUser->results) && isset($getUser->results[0]) ){
  2340.                     $user = $getUser->results[0];
  2341.                 }
  2342.             }
  2343.            
  2344.         }
  2345.        
  2346.         if (isset($user)){
  2347.             return $user;
  2348.         }
  2349.     }
  2350.    
  2351.     /******************************************
  2352.     Get nice username from url (user query var)
  2353.     ******************************************/
  2354.     function try_query_user($user_id){
  2355.         $user =  $this->get_member_by( get_query_var('up_username') );
  2356.         if ( $user ) {
  2357.             $user_id = $user->ID;
  2358.         }
  2359.         return $user_id;
  2360.     }
  2361.    
  2362.     /******************************************
  2363.     Display short user bio
  2364.     ******************************************/
  2365.     function shortbio($userid, $length=100, $fallback=null) {
  2366.         $desc = get_user_meta($userid, 'description', true);
  2367.         $desc = wp_strip_all_tags($desc);
  2368.         if (strlen($desc) > $length) {
  2369.             $desc = mb_substr($desc,0,$length, "utf-8");
  2370.             $res = $desc . '...';
  2371.         } else {
  2372.             $res = $desc;
  2373.         }
  2374.         if (!$res && $fallback){
  2375.             $res = $fallback;
  2376.         }
  2377.         return $res;
  2378.     }
  2379.    
  2380.     /******************************************
  2381.     Show meta fields in member directory
  2382.     ******************************************/
  2383.     function meta_fields($fields, $user_id) {
  2384.         $res = '';
  2385.         $arr = explode(',',$fields);
  2386.         foreach($arr as $k) {
  2387.             if(!userpro_field_is_viewable_noargs($k,$user_id))
  2388.                 continue;
  2389.             if ( get_user_meta( $user_id, $k, true) != '') {
  2390.                 $values[] = $k;
  2391.             }
  2392.         }
  2393.        
  2394.         if (isset($values) && is_array($values)){
  2395.             $n = 1;
  2396.             foreach($values as $n => $k) {
  2397.  
  2398.                 $n++;
  2399.                 if ($n == count($values)){
  2400.                 $res .= userpro_profile_data_nicename( $k, userpro_profile_data( $k, $user_id ) );
  2401.                 } else {
  2402.                 $res .= userpro_profile_data_nicename( $k, userpro_profile_data( $k, $user_id ) ) . "&nbsp;&nbsp;/&nbsp;&nbsp;";
  2403.                 }
  2404.             }
  2405.         }
  2406.        
  2407.         if (!$res) {
  2408.             $res = __('No available information','userpro');
  2409.         }
  2410.        
  2411.         return $res;
  2412.     }
  2413.    
  2414.     /******************************************
  2415.     Can view other members
  2416.     ******************************************/
  2417.     function can_view_profile( $arg=null ){
  2418.         $user_id = 0;
  2419.         $array = (array) userpro_get_option('roles_can_view_profiles');
  2420.         $array = array_merge( $array, array('administrator') );
  2421.         if ( userpro_is_logged_in() ) {
  2422.             if ($arg){
  2423.                 $user = $this->get_member_by($arg);
  2424.                 if(isset($user))
  2425.                 {
  2426.                     $user_id = $user->ID;
  2427.                     if (get_current_user_id() == $user_id){
  2428.                     return true;
  2429.                 }   }
  2430.             }
  2431.         }
  2432.         if ( userpro_get_option('allow_users_view_profiles') == 0 && userpro_is_logged_in() && $this->user_role_in_array( get_current_user_id(), $array)  ) {
  2433.             return true;
  2434.         }
  2435.         if ( userpro_get_option('allow_users_view_profiles') == 0 && !current_user_can('manage_options') ) {
  2436.             return false;
  2437.         }
  2438.         return true;
  2439.     }
  2440.    
  2441.     /******************************************
  2442.     Check if requested user is the logged in user
  2443.     ******************************************/
  2444.     function is_user_logged_user($user_id){
  2445.         if ( $user_id == get_current_user_id() ) {
  2446.             return true;
  2447.         }
  2448.         return false;
  2449.     }
  2450.    
  2451.     /******************************************
  2452.     Viewing his own profile or not
  2453.     ******************************************/
  2454.     function viewing_his_profile(){
  2455.         $id = get_current_user_id();
  2456.         $logged_id = get_current_user_id();
  2457.         if ( get_query_var('up_username') ) {
  2458.             $id = $this->get_member_by_queryvar_from_id();
  2459.         }
  2460.         if ($logged_id && $id && ( $logged_id == $id ) )
  2461.             return true;
  2462.         return false;
  2463.     }
  2464.    
  2465.     /******************************************
  2466.     Delete user
  2467.     ******************************************/
  2468.     function delete_user($user_id){
  2469.         if ( is_multisite()  ) {
  2470.             wpmu_delete_user( $user_id );
  2471.         } else {
  2472.             wp_delete_user( $user_id );
  2473.         }
  2474.     }
  2475.    
  2476.     /******************************************
  2477.     Get verified account status for user
  2478.     ******************************************/
  2479.     function get_verified_status($user_id) {
  2480.         $field = get_user_meta($user_id, 'userpro_verified', true);
  2481.         if (userpro_is_admin($user_id)) {
  2482.             //return 1;
  2483.             return $field;
  2484.         } else {
  2485.             return $field;
  2486.         }
  2487.     }
  2488.     /******************************************
  2489.      Check if user is blocked by admin or not
  2490.     ******************************************/
  2491.     function get_account_status($user_id) {
  2492.         $status = get_user_meta($user_id, 'userpro_account_status', true);
  2493.         if (userpro_is_admin($user_id)) {
  2494.             //return 1;
  2495.             return $status;
  2496.         } else {
  2497.             return $status;
  2498.         }
  2499.     }
  2500.     /******************************************
  2501.     Make the link that user has to click to
  2502.     become verified
  2503.     ******************************************/
  2504.     function accept_invite_to_verify($user_id) {
  2505.         $salt = get_user_meta($user_id, '_invite_verify', true);
  2506.         if ( $salt != '' && strlen($salt) == 20 && $this->user_exists($user_id) ){
  2507.             $url = home_url() . '/';
  2508.             $url = add_query_arg( 'act', 'verified_invitation', $url );
  2509.             $url = add_query_arg( 'user_id', $user_id, $url );
  2510.             $url = add_query_arg( 'hash_secret', $salt, $url );
  2511.             return $url;
  2512.         }
  2513.     }
  2514.    
  2515.     /******************************************
  2516.     Setup invitation verification
  2517.     ******************************************/
  2518.     function new_invitation_verify($user_id){
  2519.         $hash = wp_generate_password( $length=20, $include_standard_special_chars=false );
  2520.         update_user_meta($user_id, '_invite_verify', $hash);
  2521.         userpro_mail($user_id, 'verifyinvite');
  2522.     }
  2523.    
  2524.     /******************************************
  2525.     User already invited
  2526.     ******************************************/
  2527.     function invited_to_verify($user_id){
  2528.         return get_user_meta($user_id, '_invite_verify', true);
  2529.     }
  2530.    
  2531.     /******************************************
  2532.     Make a user verified
  2533.     ******************************************/
  2534.     function verify($user_id) {
  2535.        
  2536.         // verify him
  2537.         update_user_meta($user_id, 'userpro_verified', 1);
  2538.        
  2539.         delete_user_meta($user_id, 'userpro_verification');
  2540.         delete_user_meta($user_id, '_invite_verify');
  2541.        
  2542.         // send him a notification
  2543.         if (userpro_get_option('notify_user_verified')){
  2544.             userpro_mail($user_id, 'accountverified');
  2545.         }
  2546.        
  2547.         $role = userpro_get_option('upgrade_role_after_verfied');
  2548.         if( isset($role) && $role != 'none'){
  2549.             if(!is_super_admin($user_id)){
  2550.                 $user = new WP_User( $user_id );
  2551.                 $user->role = $role;
  2552.                 wp_update_user($user);
  2553.             }
  2554.         }
  2555.         do_action('userpro_after_user_verify', $user_id);
  2556.     }
  2557.    
  2558.     /******************************************
  2559.     Make a user unverified
  2560.     ******************************************/
  2561.     function unverify($user_id) {
  2562.    
  2563.         // verified (unverify him)
  2564.         if ( userpro_get_option('notify_user_unverified') && $this->get_verified_status($user_id) == 1 ){
  2565.             userpro_mail($user_id, 'accountunverified');
  2566.         }
  2567.        
  2568.         // make user unverified and delete his request
  2569.         update_user_meta($user_id, 'userpro_verified', 0);
  2570.         delete_user_meta($user_id, 'userpro_verification');
  2571.  
  2572.         // remove his verify request
  2573.         $requests = get_option('userpro_verify_requests');
  2574.         if (isset($requests) && is_array($requests)){
  2575.             foreach($requests as $k => $id){
  2576.                 if ($id == $user_id){
  2577.                     unset($requests[$k]);
  2578.                 }
  2579.             }
  2580.             update_option('userpro_verify_requests', $requests);
  2581.         }
  2582.        
  2583.         do_action('userpro_after_user_unverify', $user_id);
  2584.     }
  2585.     /******************************************
  2586.      Make an account blocked
  2587.     ******************************************/
  2588.     function block_account($user_id) {
  2589.         // Block user
  2590.         update_user_meta($user_id, 'userpro_account_status', 1);
  2591.                 $this->clear_cache();
  2592.         userpro_mail($user_id, 'accountblocked');
  2593.         do_action('userpro_after_account_blocked', $user_id);
  2594.     }
  2595.    
  2596.     /******************************************
  2597.      Make an account unblocked
  2598.     ******************************************/
  2599.     function unblock_account($user_id) {
  2600.         // Unblock user
  2601.         update_user_meta($user_id, 'userpro_account_status', 0);
  2602.                 $this->clear_cache();
  2603.         userpro_mail($user_id, 'accountunblocked');
  2604.         do_action('userpro_after_account_unblocked', $user_id);
  2605.     }
  2606.     /******************************************
  2607.     Checks if user can request verification
  2608.     ******************************************/
  2609.     function request_verification($user_id){
  2610.         if ( userpro_get_option('allow_users_verify_request') && $this->get_verified_status($user_id) != 1 && !$this->request_verification_pending($user_id) && $user_id == get_current_user_id())
  2611.             return true;
  2612.         return false;
  2613.     }
  2614.    
  2615.     /******************************************
  2616.     Checks if the verification is pending
  2617.     ******************************************/
  2618.     function request_verification_pending($user_id) {
  2619.         $status = get_user_meta($user_id, 'userpro_verification', true);
  2620.         if ($status == 'pending')
  2621.             return true;
  2622.         return false;
  2623.     }
  2624.    
  2625.     /******************************************
  2626.     Make a verification request for user
  2627.     ******************************************/
  2628.     function new_verification_request($username) {
  2629.         $user = $this->get_member_by($username);
  2630.         update_user_meta($user->ID, 'userpro_verification', 'pending');
  2631.         $requests = get_option('userpro_verify_requests');
  2632.         $requests[] = $user->ID;
  2633.         update_option('userpro_verify_requests', $requests);
  2634.         userpro_mail($user->ID,'verifyuser');
  2635.     }
  2636.    
  2637.     /******************************************
  2638.     Set user's role based on ID, role
  2639.     ******************************************/
  2640.     function set_role($user_id, $role) {
  2641.         $wp_user_object = new WP_User( $user_id );
  2642.         $wp_user_object->set_role( $role );
  2643.     }
  2644.    
  2645.     /******************************************
  2646.     Get user's role based on ID, role
  2647.     ******************************************/
  2648.     function get_role_nice($user) {
  2649.         $user_roles = $user->roles;
  2650.         if (isset($user_roles) && is_array($user_roles)){
  2651.             $user_role = array_shift($user_roles);
  2652.             return userpro_user_role($user_role);
  2653.         }
  2654.         return '';
  2655.     }
  2656.    
  2657.     /******************************************
  2658.     Assign default role after registration
  2659.     ******************************************/
  2660.     function default_role($user_id, $form=null){
  2661.        
  2662.         if ( isset($form['form_role']  ) ) {
  2663.        
  2664.             $this->set_role( $user_id, $form['form_role'] );
  2665.        
  2666.         }
  2667.         else if(!empty($_SESSION['form_role']))
  2668.         {
  2669.             $this->set_role( $user_id,$_SESSION['form_role']);
  2670.            
  2671.         }
  2672.         else {
  2673.        
  2674.             if (userpro_get_option('default_role') && !isset($form['role']) ){
  2675.                 if ( userpro_get_option('default_role')  == 'no_role') {
  2676.                     $role = '';
  2677.                 } else {
  2678.                     $role = userpro_get_option('default_role');
  2679.                 }
  2680.                 $this->set_role( $user_id, $role );
  2681.             }
  2682.        
  2683.         }
  2684.     }
  2685.    
  2686.     /******************************************
  2687.     Returns 1/0 for Facebook connected profiles
  2688.     ******************************************/
  2689.     function is_facebook_user($user_id) {
  2690.         $fbid = get_user_meta($user_id, 'userpro_facebook_id', true);
  2691.         if ($fbid)
  2692.             return true;
  2693.         return false;
  2694.     }
  2695.    
  2696.     /******************************************
  2697.     Returns 1/0 for Twitter connected profiles
  2698.     ******************************************/
  2699.     function is_twitter_user($user_id) {
  2700.         $twitter_id = get_user_meta($user_id, 'twitter_oauth_id', true);
  2701.         if ($twitter_id)
  2702.             return true;
  2703.         return false;
  2704.     }
  2705.    
  2706.     /******************************************
  2707.     Returns 1/0 for Google connected profiles
  2708.     ******************************************/
  2709.     function is_google_user($user_id) {
  2710.         $google_id = get_user_meta($user_id, 'userpro_google_id', true);
  2711.         if ($google_id)
  2712.             return true;
  2713.         return false;
  2714.     }
  2715.    
  2716.     /******************************************
  2717.     Default display name
  2718.     ******************************************/
  2719.     function set_default_display_name($user_id, $username) {
  2720.         $display_name = $username;
  2721.         if ($this->display_name_exists( $display_name )){
  2722.             $display_name = $this->unique_display_name($display_name);
  2723.         }
  2724.        
  2725.         wp_update_user( array( 'ID' => $user_id, 'display_name' => $display_name ) );
  2726.         update_user_meta($user_id, 'display_name', $display_name);
  2727.     }
  2728.    
  2729.     /******************************************
  2730.     Create a new user
  2731.     ******************************************/
  2732.     function new_user($user_login, $user_password, $user_email, $form, $type, $approved=1) {
  2733.         global $wpdb;
  2734.        
  2735.         $errors = new WP_Error();
  2736.        
  2737.         $user_id = wp_insert_user( array(
  2738.                 'user_login'   => $user_login,
  2739.                 'user_pass'    => $user_password,
  2740.                 'display_name' => sanitize_title( $user_login ),
  2741.                 'user_email'   => $user_email
  2742.         ) );
  2743.           add_filter( 'send_password_change_email', '__return_false');
  2744.         if ( is_wp_error( $user_id ) || empty( $user_id ) ) {
  2745.             /* @todo: Manage error conditions */
  2746.             $errors->add( 'registerfail', sprintf( __( '<strong>ERROR</strong>: Couldn&#8217;t register you. Please contact the webmaster.', 'userpro' ) ) );
  2747.             return $errors;
  2748.         }
  2749.        
  2750.         $this->default_role($user_id, $form);
  2751.        
  2752.         if ($type == 'standard'){
  2753.            
  2754.             $this->set_default_display_name($user_id, $user_login);
  2755.         }
  2756.        
  2757.         if ($type == 'facebook') {
  2758.             userpro_update_profile_via_facebook($user_id, $form );
  2759.             $this->facebook_save_profile_pic( $user_id, $form['profilepicture'] );
  2760.         } elseif ($type == 'twitter') {
  2761.             userpro_update_profile_via_twitter($user_id, $form );
  2762.             $this->twitter_save_profile_pic( $user_id, $form );
  2763.         }
  2764.         elseif ($type == 'linkedin')
  2765.         {                  
  2766.                 $this->instagram_save_profile_pic($user_id,$form);
  2767.                 $this->set_default_display_name($user_id, $user_login);
  2768.         }
  2769.         elseif ($type == 'instagram')
  2770.         {
  2771.             $this->instagram_save_profile_pic($user_id,$form);
  2772.             $this->set_default_display_name($user_id, $user_login);
  2773.                    
  2774.         }  
  2775.        
  2776.          elseif ($type == 'google') {
  2777.             userpro_update_profile_via_google($user_id, $form );
  2778.             $this->google_save_profile_pic( $user_id, $form );
  2779.         } else {
  2780.             userpro_update_user_profile( $user_id, $form, $action='new_user' );
  2781.         }
  2782.        
  2783.         if ($approved==1){
  2784.             userpro_mail($user_id, 'newaccount', $user_password, $form );
  2785.             do_action('userpro_after_new_registration', $user_id);
  2786.         }
  2787.        
  2788.         return $user_id;
  2789.     }
  2790.    
  2791.     /******************************************
  2792.     Get the user profile data
  2793.     ******************************************/
  2794.     function extract_profile_for_mail($user_id, $form) {
  2795.         $output = '';
  2796.         $customfieldarray = array();
  2797.         foreach($form as $k=>$v){
  2798.             if ($this->field_label( $k ) != '' && !strstr($k, 'pass') ) {
  2799.                 $val = userpro_profile_data($k, $user_id);
  2800.                 if ($k == 'gender') {
  2801.                     $val = userpro_profile_data_nicename( $k, userpro_profile_data($k, $user_id) );
  2802.                 }
  2803.                 if (is_array($val)){
  2804.                     $val = implode(', ',$val);
  2805.                 }
  2806.                 $output .= $this->field_label($k) . ': '. $val . "\r\n";
  2807.                 $customfieldarray['{USERPRO_'.$k.'}'] = $val;
  2808.             }
  2809.            
  2810.         }
  2811.         return array( 'output'=>$output , 'custom_fields'=>$customfieldarray);
  2812.     }
  2813.    
  2814.     /******************************************
  2815.     Return true or false if user can view the
  2816.     private content or not
  2817.     ******************************************/
  2818.     function can_view_private_content($restrict_to_verified=null,$restrict_to_roles=null){
  2819.         if (!userpro_is_logged_in()) {
  2820.             return '-1';
  2821.         } else {
  2822.             if(userpro_get_option('restricted_page_verified')=="1" &&  $this->get_verified_status( get_current_user_id() ) )
  2823.             {
  2824.             $user = get_userdata( get_current_user_id() );
  2825.             $user_role = array_shift($user->roles);
  2826.  
  2827.             if ( ( $restrict_to_verified ==1 && $this->get_verified_status( get_current_user_id() ) ) ||
  2828.                     ( $restrict_to_roles != '' && in_array($user_role, explode(',',$restrict_to_roles)) ) ||
  2829.                   ( !$restrict_to_verified && !$restrict_to_roles )
  2830.                 ) {
  2831.                 return '1';
  2832.             } else {
  2833.                 return '-2';
  2834.             }
  2835.             }
  2836.             else
  2837.             {
  2838.                 if(userpro_get_option('restricted_page_verified')=="0")
  2839.                 {
  2840.                     $user = get_userdata( get_current_user_id() );
  2841.                     $user_role = array_shift($user->roles);
  2842.                    
  2843.                     if ( ( $restrict_to_verified ==1 && $this->get_verified_status( get_current_user_id() ) ) ||
  2844.                             ( $restrict_to_roles != '' && in_array($user_role, explode(',',$restrict_to_roles)) ) ||
  2845.                             ( !$restrict_to_verified && !$restrict_to_roles )
  2846.                     ) {
  2847.                         return '1';
  2848.                     } else {
  2849.                         return '-2';
  2850.                     }
  2851.                    
  2852.                 }
  2853.             }
  2854.            
  2855.         }
  2856.     }
  2857.    
  2858.    
  2859.     /******************************************
  2860.     Manual display for facebook login button
  2861.     ******************************************/
  2862.     function facebook_login( $args=array() ){
  2863.         return userpro_facebook_connect_manual( $args );
  2864.     }
  2865.    
  2866.     /******************************************
  2867.     Move file to user directory
  2868.     ******************************************/
  2869.     function move_file($user_id, $file, $destination){
  2870.         file_put_contents( $this->get_uploads_dir($user_id) . $destination, file_get_contents( $file ));
  2871.     }
  2872.    
  2873.     /******************************************
  2874.     Save a photo from google to profile
  2875.     ******************************************/
  2876.     function google_save_profile_pic($user_id, $form) {
  2877.         $this->do_uploads_dir( $user_id );
  2878.  
  2879.         if ($form['image']['url']){
  2880.             $form['image']['url'] = str_replace('?sz=50','',$form['image']['url']);
  2881.             $unique_id = uniqid();
  2882.             $this->move_file( $user_id, $form['image']['url'], $unique_id . '.jpg' );
  2883.             update_user_meta($user_id, 'profilepicture', $this->get_uploads_url($user_id) . $unique_id . '.jpg' );
  2884.         }
  2885.        
  2886.     }
  2887.    
  2888.     /******************************************
  2889.     Save a photo from twitter to profile
  2890.     ******************************************/
  2891.     function twitter_save_profile_pic($user_id, $form) {
  2892.         $this->do_uploads_dir( $user_id );
  2893.        
  2894.         if ($form['profile_image_url']){
  2895.  
  2896.             $form['profile_image_url'] = str_replace('_normal','',$form['profile_image_url']);
  2897.             $unique_id = uniqid();
  2898.             $this->move_file( $user_id, $form['profile_image_url'], $unique_id . '.jpg' );
  2899.             update_user_meta($user_id, 'profilepicture', $this->get_uploads_url($user_id) . $unique_id . '.jpg' );
  2900.            
  2901.         }
  2902.    
  2903.     }
  2904.    
  2905.     /******************************************
  2906.     Save user profile picture from facebook
  2907.     ******************************************/
  2908.     function facebook_save_profile_pic($user_id, $profilepicture, $method=null){
  2909.         $method = userpro_get_option('picture_save_method');
  2910.         $unique_id = uniqid();
  2911.        
  2912.         update_user_meta($user_id, 'facebook_pic_url', $profilepicture);
  2913.         if ($method == 'internal') {
  2914.        
  2915.             $this->do_uploads_dir( $user_id );
  2916.             $this->move_file( $user_id, $profilepicture, $unique_id . '.jpg' );
  2917.             update_user_meta($user_id, 'profilepicture', $this->get_uploads_url($user_id) . $unique_id . '.jpg' );
  2918.            
  2919.         } else {
  2920.        
  2921.             update_user_meta($user_id, 'profilepicture', $profilepicture );
  2922.            
  2923.         }
  2924.     }
  2925.  
  2926.     /******************************************
  2927.     Save user profile picture from Instagram
  2928.     ******************************************/
  2929.     function instagram_save_profile_pic($user_id, $profilepicture, $method=null){
  2930.         $method = userpro_get_option('picture_save_method');
  2931.         $unique_id = uniqid();
  2932.         update_user_meta($user_id, 'instagram_pic_url', $profilepicture);
  2933.         if ($method == 'internal') {
  2934.        
  2935.             $this->do_uploads_dir( $user_id );
  2936.             $this->move_file( $user_id, $profilepicture, $unique_id . '.jpg' );
  2937.             update_user_meta($user_id, 'profilepicture', $this->get_uploads_url($user_id) . $unique_id . '.jpg' );
  2938.                
  2939.         } else {
  2940.        
  2941.             update_user_meta($user_id, 'profilepicture', $profilepicture );
  2942.                
  2943.         }
  2944.     }
  2945.     /******************************************
  2946.     Initial search results
  2947.     ******************************************/
  2948.     function memberlist_in_search_mode($args){
  2949.         if (isset($args['turn_off_initial_results']) && ( !isset($_GET['searchuser']) && !isset($_GET['emd-search']))) {
  2950.             return false;
  2951.         }
  2952.         return true;
  2953.     }
  2954.    
  2955.     /******************************************
  2956.     Online users count
  2957.     ******************************************/
  2958.     function online_users_count($count){
  2959.         if ($count == 1) {
  2960.         return sprintf(__('There are %s user online on the site.','userpro'), $count);
  2961.         } else {
  2962.         return sprintf(__('There are %s users online on the site.','userpro'), $count);
  2963.         }
  2964.     }
  2965.  
  2966.     function connection($user_id)
  2967.     {
  2968.        
  2969.         $userids=get_user_meta($user_id,'_userpro_users_request',true );
  2970.         return $userids;
  2971.        
  2972.        
  2973.     }
  2974.     function connetions_count($user_id){
  2975.         $arr =  get_user_meta($user_id,'_userpro_connected_userlist', true);
  2976.         if (is_array($arr) && !empty($arr)){
  2977.         $count = count($arr);
  2978.         } else {
  2979.         $count = 0;
  2980.         }
  2981.         $count = number_format_i18n($count);
  2982.         if($count == 1)
  2983.             return sprintf(__('<span>%s</span> Connection','userpro'), $count);
  2984.         else
  2985.             return sprintf(__('<span>%s</span> Connections','userpro'), $count);
  2986.     }
  2987.    
  2988.     function up_enqueue_scripts_styles(){
  2989.         /* CSS */
  2990.         /* lightview */
  2991.         if (userpro_get_option('lightbox')) {
  2992.             wp_register_style('userpro_lightview', userpro_url . 'css/lightview/lightview.css' );
  2993.             wp_enqueue_style('userpro_lightview');
  2994.         }
  2995.        
  2996.         if ( !userpro_get_option('rtl') ) {
  2997.                 $css = 'css/userpro.min.css';
  2998.         } else {
  2999.             $css = 'css/userpro-rtl.min.css';
  3000.                
  3001.         }
  3002.         wp_register_style('userpro_min', userpro_url . $css );
  3003.         wp_enqueue_style('userpro_min');
  3004.        
  3005.         wp_enqueue_style('userpro_jquery_ui_style', userpro_url . 'css/userpro-jquery-ui.css');
  3006.  
  3007.         if (userpro_get_option('lightbox')) {
  3008.             wp_register_script('userpro_swf', userpro_url .'scripts/swfobject.js' ,'','',true);
  3009.             wp_enqueue_script('userpro_swf');
  3010.            
  3011.             wp_register_script('userpro_spinners', userpro_url . 'scripts/spinners/spinners.min.js' ,'','',true);
  3012.             wp_enqueue_script('userpro_spinners');
  3013.            
  3014.             wp_register_script('userpro_lightview', userpro_url . 'scripts/lightview/lightview.js','','',true );
  3015.             wp_enqueue_script('userpro_lightview');
  3016.         }
  3017.  
  3018.        
  3019.         wp_register_script('userpro_min', userpro_url . 'scripts/scripts.min.js','','',true );
  3020.         wp_enqueue_script('userpro_min');
  3021.         $userpro_limit_categories = userpro_get_option('limit_categories' );
  3022.         wp_localize_script('userpro_min', 'userpro_frontend_publisher_data', array( 'userpro_limit_categories' => $userpro_limit_categories ) );
  3023.        
  3024.         wp_register_script('performance', userpro_url . 'scripts/performance.js','','',true );
  3025.         wp_enqueue_script('performance');
  3026.         if( userpro_get_option('userpro_enable_webcam') ){
  3027.             wp_enqueue_script('up-webcam-js', userpro_url . 'scripts/webcam.min.js','','',true );
  3028.         }
  3029.  
  3030.         wp_enqueue_script( 'userpro_encrypt_js', userpro_url . 'scripts/userpro.encrypt.js','','',true);
  3031.         ///////////////
  3032.        
  3033.     }
  3034.    
  3035.     /******************** Get connection count *****************/
  3036.    
  3037.     function get_connection_count( $user_id =0 ){
  3038.         $connections = get_user_meta($user_id,'_userpro_connected_userlist',true);
  3039.         if(!empty($connections)){
  3040.             return count( $connections );
  3041.         }
  3042.         return 0;  
  3043.     }
  3044.    
  3045. }
  3046.  
  3047. function otgs_test(){
  3048.     $userpro = new userpro_api();
  3049. }
  3050. add_action( 'wp', 'otgs_test' );
Add Comment
Please, Sign In to add comment