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); ?>
0, 'secondary_id'=>0, 'type'=>'presale', 'user'=>array( 'id'=> 0, 'name'=> 'Guest', 'image'=> $avatar, 'type'=>'nonlogged', 'ip'=>$_SERVER["REMOTE_ADDR"], ), 'settings'=>array( 'chat_form'=>(empty($settings['chat_form'])?0:1), 'offline_notifications'=>(empty($settings['offline_notifications'])?0:1), ), 'api_url'=>home_url().'/wp-json/wplms/v1/chat', 'live_api_url'=>home_url().'/wp-json/wplms/v1/live', 'notify_users'=>$notify_users, 'translations'=>array( 'welcome'=> $settings['welcome_message'], 'chat_title'=>$settings['chat_title'], 'chat_subtitle'=>$settings['chat_subtitle'], 'first_message'=>__('Write first message','wplms-chat'), 'start_conversation'=>__('Start Conversation','wplms-chat'), 'start_chat'=>__('Start Chat','wplms-chat'), 'join_chat'=>__('Join Chat','wplms-chat'), 'enter_name'=>__('Enter Name','wplms-chat'), 'enter_email'=>__('Enter Email','wplms-chat'), 'load_chat'=>__('Load chat','wplms-chat'), 'set_default'=>__('Set as Default','wplms-chat'), 'delete'=>__('Delete chat','wplms-chat'), 'search_directory'=>__('Search Directory','wplms-chat'), 'no_member_found'=>__('No online member found','wplms-chat'), 'no_chat_member'=>__('No online chat agents found','wplms-chat'), 'no_my_chats'=>__('No previous chats found ! Click start conversation to start chat','wplms-chat'), 'invited_chat'=>__("You're invited to chat",'wplms-chat'), 'online'=>__('Online','wplms-chat'), 'offline'=>__('Offline','wplms-chat'), 'members'=>__('Members','wplms-chat'), 'mychats'=>__('Chats','wplms-chat'), 'chat'=>__('Chat','wplms-chat'), 'invite'=>__('Invite','wplms-chat'), 'invited'=>__('Invited','wplms-chat'), 'you'=>__('You','wplms-chat'), 'others'=>__('Others','wplms-chat'), 'hours'=>__('hours','wplms-chat'), 'minutes'=>__('minutes','wplms-chat'), 'exit_chat'=>__('Exit ','wplms-chat'), 'notifications'=>__('Notifications','wplms-chat'), 'guest'=>__('Guest','wplms-chat'), 'enter_name'=>__('Enter name','wplms-chat'), 'enter_email'=>__('Enter email','wplms-chat'), 'start_chat'=>__('Start Chat','wplms-chat'), 'new_conversation'=>__('New conversation','wplms-chat'), 'chat_invite'=>__("You're invited to chat",'wplms-chat'), 'accept'=>__('Accept','wplms-chat'), 'reject'=>__('Reject','wplms-chat'), 'days'=>__('days','wplms-chat'), 'istyping'=>__('is typing ...','wplms-chat'), ), ); } if(!empty($args)){ if(!empty($args['translations'])){ $args['translations'] = array_merge($data['translations'],$args['translations']); } $data = array_merge($data,$args); } $data = apply_filters('wplms_chat_after_data',$data); //DEvelopment wp_enqueue_script('wplms_chat','http://localhost:3000/static/js/bundle.js',array(),10,true); //Live //wp_enqueue_script('wplms_chat',plugins_url('../assets/js/wplms_chat.js',__FILE__),array(),WPLMS_CHAT_VERSION,true); wp_localize_script('wplms_chat','wplms_chat',$data); wp_enqueue_style('wplms_chat',plugins_url('../assets/js/wplms_chat.css',__FILE__),array(),WPLMS_CHAT_VERSION); } } WPLMS_Chat_Init::init();