| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/test20.chuangfenglink.xyz/wp-content/plugins/chatway-live-chat/app/ |
Upload File : |
<?php
/**
* Chatway internal user APIs
*
* @author : Chatway
* @license : GPLv3
* */
namespace Chatway\App;
/**
* @since 1.0.0
* Create an internal API group for users by extending Api class
*/
class User extends Api
{
use Singleton;
public function config() {
// this prefix will used in api endpoint - example: /chatway/v1/user
$this->prefix = 'user';
}
/**
* @method POST
* @api /chatway/v1/user/save
*
* Save user current user data. Initiall it receives user identifier and token
*/
public function post_save() {
$params = $this->request->get_params();
$user_identifier = sanitize_text_field( isset( $params['user_identifier'] ) ? $params['user_identifier'] : '' );
$token = sanitize_text_field( isset( $params['token'] ) ? $params['token'] : '' );
// clear the cache of the user is new
if (function_exists('chatway_clear_all_caches')) {
chatway_clear_all_caches();
}
// delete all data
User::clear_chatway_keys();
if ( ! empty( $user_identifier ) && ! empty( $token ) ) {
// save user identifier and token to DB
add_option( 'chatway_user_identifier', $user_identifier );
add_option( 'chatway_user_cache_identifier', $user_identifier );
add_option( 'chatway_token', $token );
return [
'code' => 200,
'message' => 'success',
];
}
return [
'code' => 401,
'message' => 'error',
];
}
/**
* @method GET
* @api /chatway/v1/user/logout
*
* Remote everything related to the current user from DB
*/
public function get_logout() {
ExternalApi::sync_wp_plugin_version(\Chatway::is_woocomerce_active(), 0);
User::clear_chatway_keys();
if (function_exists('chatway_clear_all_caches')) {
chatway_clear_all_caches();
}
return [
'code' => 200,
'message' => 'success',
];
}
/**
* Retrieves the unread messages count from an external API and caches it as a transient.
*
* @return array An associative array containing the count of unread messages ('count') and a status code ('code').
*/
public function get_count() {
delete_transient( 'chatway_unread_messages_count' );
$count = ExternalApi::get_unread_messages_count();
set_transient( 'chatway_unread_messages_count', $count, 5*60 );
return ['count' => $count, 'code' => 200];
}
/**
* Removes all Chatway-related options from the WordPress options table.
*
* @return void
* Method does not return any value.
*/
static function clear_chatway_keys() {
delete_option( 'chatway_redirection' );
delete_option( 'chatway_user_identifier' );
delete_option( 'chatway_api_secret_license_key' );
delete_option( 'chatway_token' );
delete_option( 'chatway_wp_plugin_version' );
delete_option( 'chatway_secret_key' );
delete_option( 'chatway_has_auth_error' );
}
}