get_firebase_admin_token(); echo $token; if(empty($this->settings)){ $this->settings = get_option(WPLMS_CHAT_OPTION); } if(!empty($this->settings['firebase_database_url'])){ $response = wp_safe_remote_post($this->settings['firebase_database_url'].'/.settings/rules.json?access_token='.$token,array( 'method'=>'PUT', 'timeout'=>15, 'body'=>json_encode(array( 'rules'=>array( 'read'=>'auth != null', 'write'=>'auth != null', 'notifications'=>array( ".indexOn"=>array("status") ), ), )) )); } update_option('wplms_chat_structure',WPLMS_CHAT_STRUCTURE); } die(); } function get_admin_token(){ $chat = WPLMS_Live::init(); if(current_user_can('manage_options')){ echo $chat->get_firebase_admin_token(); update_option('wplms_chat_structure',WPLMS_CHAT_STRUCTURE); } die(); } function get_instructor_token(){ $chat = WPLMS_Live::init(); if(current_user_can('edit_posts')){ echo $chat->get_firebase_instructor_token(); } die(); } function loggedin_user($args){ if(!is_user_logged_in()) return $args; $user_id = get_current_user_id(); $avatar = bp_course_get_instructor_avatar_url($user_id); if(empty($avatar) && function_exists('vibe_get_option')){ $avatar = vibe_get_option('default_avatar'); } if(empty($avatar)){ $avatar = plugins_url(__FILE__,'../assets/images/avatar.jpg'); } $id = get_current_user_id(); $args['user'] = apply_filters('wplms_chat_user',array( 'id'=> $id, 'name'=> bp_core_get_user_displayname($id), 'image'=> $avatar, 'status'=>1, // 1 online 0 offline 'type'=>(current_user_can('manage_options')?'administrator':(current_user_can('edit_posts')?'instructor':'student')) )); if(empty($args['type'])){ $args['type']='general'; } return $args; } function get_settings(){ if(empty($this->settings)){ $this->settings = get_option(WPLMS_CHAT_OPTION); } return $this->settings; } function add_chat_in_profile_menu(){ $this->get_settings(); if(empty($this->settings['profile_chat'])) return; global $bp; //Add learningpath in profile menu bp_core_new_nav_item( array( 'name' => __('CHAT','wplms-chat'), 'slug' => WPLMS_CHAT_SLUG, 'item_css_id' => 'wplms_chat', 'screen_function' => array($this,'show_chat_screen'), 'default_subnav_slug' => 'home', 'position' => 50 ) ); } function show_chat_screen(){ add_action( 'bp_template_title', function(){ echo _x('Live Chats','Profile chat title','wplms-chat'); }); add_action( 'bp_template_content', array($this,'wplms_my_profile_chats')); bp_core_load_template( 'members/single/plugins'); } function wplms_my_profile_chats(){ $user_id = bp_displayed_user_id(); add_filter('wplms_chat_class',function($x){ return 'profile_chat'; }); echo do_shortcode('[wplms_chat type="personal" primary_id="" user_id="'.$user_id.'"]'); } function wplms_chat_shortcode( $atts, $content = null ) { extract(shortcode_atts(array( 'type' => '', 'primary_id'=>'', 'notify_users'=>'', 'chat_title'=>'', 'chat_subtitle'=>'', 'welcome_message'=>'', 'user_id'=>'', 'class'=>'', ), $atts)); $return = ''; $args = array(); $args['type']=$type; $args['primary_id']=$primary_id; $args['notify_users']=$notify_users; $args['class']=$class; if(is_user_logged_in() && empty($user_id)){ $user_id = get_current_user_id(); } if(!empty($user_id)){ $avatar = get_avatar($user_id); if(empty($avatar)){ if(function_exists('vibe_get_option')){ $avatar = vibe_get_option('default_avatar'); } if(empty($avatar)){ $avatar = plugins_url(__FILE__,'../assets/images/avatar.jpg'); } } $wp_user = get_userdata($user_id); $user=array( 'id'=> $user_id, 'name'=> $wp_user->display_name, 'image'=> $avatar, 'type'=>'nonlogged', 'ip'=>$_SERVER["REMOTE_ADDR"], ); $args['user']=$user; } if(!empty($chat_title)){ $args['translations']['chat_title']=$chat_title; } if(!empty($chat_subtitle)){ $args['translations']['chat_subtitle']=$chat_subtitle; } if(!empty($welcome_message)){ $args['translations']['welcome_message']=$welcome_message; } $this->wplms_chat($args); remove_action('wp_footer',array($this,'wplms_chat'),11); } function show_chat_globally(){ if(empty($this->settings)){ $this->settings = get_option(WPLMS_CHAT_OPTION); } $settings = $this->settings; if(empty($settings['show_chat'])) return; $show_chat_option = false; switch($settings['show_chat']){ case 'all': $show_chat_option = true; break; case 'read': if(is_user_logged_in()){ $show_chat_option = true; } break; case 'edit_posts': if(current_user_can('edit_posts')){ $show_chat_option = true; } break; default: $show_chat_option = apply_filters('wplms_chat_show_chat',$show_chat_option,$settings); break; } if(empty($show_chat_option)) return; add_action('wp_footer',array($this,'wplms_chat'),11); } function stop_chat(){ return apply_filters('wplms_stop_chat',false); } function wplms_chat($args=null){ if($this->stop_chat()) return; $settings = $this->get_settings(); $class='bottomright'; if(!empty($args['class'])){ $class=$args['class']; } $chat_class = apply_filters('wplms_chat_class',$class); ?>