--- a/wpguppy-lite/admin/settings/settings.php
+++ b/wpguppy-lite/admin/settings/settings.php
@@ -196,7 +196,7 @@
function get_wpguppy_whatsapp_user_info() {
$json = array();
- $user_id = !empty($_GET['user_id']) ? $_GET['user_id'] : '';
+ $user_id = !empty($_POST['user_id']) ? $_POST['user_id'] : '';
if( !current_user_can('manage_options') || empty($user_id) ){
$json['type'] = 'error';
--- a/wpguppy-lite/includes/class-wp-guppy-rest-api.php
+++ b/wpguppy-lite/includes/class-wp-guppy-rest-api.php
@@ -1,22 +1,25 @@
<?php
global $guppySetting;
-if(!empty($guppySetting['rt_chat_settings'])
+if (
+ !empty($guppySetting['rt_chat_settings'])
&& $guppySetting['rt_chat_settings'] == 'pusher'
- && $guppySetting['pusher']=='enable'){
- require_once(WP_GUPPY_LITE_DIRECTORY.'libraries/pusher/vendor/autoload.php');
+ && $guppySetting['pusher'] == 'enable'
+) {
+ require_once(WP_GUPPY_LITE_DIRECTORY . 'libraries/pusher/vendor/autoload.php');
}
-require_once(WP_GUPPY_LITE_DIRECTORY.'libraries/jwt/vendor/autoload.php');
+require_once(WP_GUPPY_LITE_DIRECTORY . 'libraries/jwt/vendor/autoload.php');
/** Requiere the JWT library. */
+
use FirebaseJWTJWT;
use FirebaseJWTKey;
if (!class_exists('WP_GUPPY_LITE_RESTAPI')) {
- /**
- * REST API Module
- *
- * @package WP Guppy
- */
+ /**
+ * REST API Module
+ *
+ * @package WP Guppy
+ */
/**
* Register all rest api routes & function
@@ -40,7 +43,8 @@
* @author wp-guppy <wpguppy@gmail.com>
*/
- class WP_GUPPY_LITE_RESTAPI extends WP_REST_Controller{
+ class WP_GUPPY_LITE_RESTAPI extends WP_REST_Controller
+ {
/**
* The unique identifier of this plugin.
@@ -48,7 +52,7 @@
* @since 1.0.0
* @access private
* @var string $plugin_name The string used to uniquely identify this plugin.
- */
+ */
private $plugin_name;
/**
@@ -68,7 +72,7 @@
* @since 1.0.0
* @access private
* @var string $restapiversion rest api version
- */
+ */
private $restapiversion = 'v2';
/**
@@ -97,7 +101,7 @@
* @var string $version The current version of the plugin.
*/
private $guppyModel;
-
+
/**
* Guppy Setting
*
@@ -135,34 +139,36 @@
* @var string $version The current version of the plugin.
*/
- public $userId;
+ public $userId;
+
+ /**
+ * Initialize Singleton
+ *
+ * @var [void]
+ */
+
+ private static $_instance = null;
/**
- * Initialize Singleton
- *
- * @var [void]
- */
-
- private static $_instance = null;
-
- /**
- * Call this method to get singleton
- *
- * @return wp-guppy Instance
- */
- public static function instance($plugin_name, $version){
- if (self::$_instance === null) {
- self::$_instance = new WP_GUPPY_LITE_RESTAPI($plugin_name, $version);
- }
- return self::$_instance;
- }
+ * Call this method to get singleton
+ *
+ * @return wp-guppy Instance
+ */
+ public static function instance($plugin_name, $version)
+ {
+ if (self::$_instance === null) {
+ self::$_instance = new WP_GUPPY_LITE_RESTAPI($plugin_name, $version);
+ }
+ return self::$_instance;
+ }
/**
* Initialize the collections used to maintain the rest api routes.
*
* @since 1.0.0
*/
- public function __construct($plugin_name, $version) {
+ public function __construct($plugin_name, $version)
+ {
$this->plugin_name = $plugin_name;
$this->version = $version;
@@ -170,22 +176,26 @@
$guppyModel = WPGuppy_Model::instance();
$this->guppyModel = $guppyModel;
- add_action('wp_enqueue_scripts', array(&$this,'registerGuppyConstant'),90);
+ add_action('wp_enqueue_scripts', array(&$this, 'registerGuppyConstant'), 90);
$this->registerRestRoutes();
global $guppySetting;
$this->guppySetting = $guppySetting;
$this->showRec = !empty($this->guppySetting['showRec']) ? $this->guppySetting['showRec'] : 20;
- if(!empty($this->guppySetting['rt_chat_settings'])
+ if (
+ !empty($this->guppySetting['rt_chat_settings'])
&& $this->guppySetting['rt_chat_settings'] == 'pusher'
- && $this->guppySetting['pusher']=='enable'){
+ && $this->guppySetting['pusher'] == 'enable'
+ ) {
$appId = $this->guppySetting['option']['app_id'];
$publicKey = $this->guppySetting['option']['app_key'];
$secretKey = $this->guppySetting['option']['app_secret'];
$appCluster = $this->guppySetting['option']['app_cluster'];
- if(!empty($appId)
- && !empty($publicKey)
- && !empty($secretKey)
- && !empty($appCluster)){
+ if (
+ !empty($appId)
+ && !empty($publicKey)
+ && !empty($secretKey)
+ && !empty($appCluster)
+ ) {
$options = array(
'useTLS' => false,
'cluster' => $appCluster
@@ -199,174 +209,175 @@
* Register Guppy Constants
*
* @since 1.0.0
- */
+ */
- public function registerRestRoutes(){
+ public function registerRestRoutes()
+ {
- add_action('rest_api_init', function() {
+ add_action('rest_api_init', function () {
- register_rest_route($this->restapiurl.'/'. $this->restapiversion , 'channel-authorize' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'channel-authorize', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array(&$this, 'guppyChannelAuthorize'),
'args' => array(),
- 'permission_callback' => '__return_true',
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
- register_rest_route($this->restapiurl.'/'. $this->restapiversion , 'load-guppy-users' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'load-guppy-users', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(&$this, 'getGuppyUsers'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
- register_rest_route($this->restapiurl.'/'. $this->restapiversion , 'load-guppy-friend-requests' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'load-guppy-friend-requests', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(&$this, 'getGuppyFriendRequests'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
- register_rest_route($this->restapiurl.'/'. $this->restapiversion , 'user-login' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'user-login', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array(&$this, 'userAuth'),
'args' => array(),
- 'permission_callback' => '__return_true',
+ 'permission_callback' => '__return_true',
));
- register_rest_route($this->restapiurl.'/'. $this->restapiversion , 'load-profile-info' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'load-profile-info', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(&$this, 'getProfileInfo'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
- register_rest_route($this->restapiurl.'/'. $this->restapiversion , 'load-unread-count' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'load-unread-count', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(&$this, 'getUnreadCount'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
- register_rest_route($this->restapiurl.'/'. $this->restapiversion , 'update-profile-info' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'update-profile-info', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array(&$this, 'updateProfileInfo'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
-
- register_rest_route($this->restapiurl.'/'. $this->restapiversion , 'load-guppy-contacts' , array(
+
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'load-guppy-contacts', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(&$this, 'getGuppyContactList'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
- register_rest_route($this->restapiurl.'/'.$this->restapiversion , 'send-guppy-invite' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'send-guppy-invite', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array(&$this, 'sendGuppyInvite'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
- register_rest_route($this->restapiurl.'/'.$this->restapiversion , 'load-guppy-messages-list' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'load-guppy-messages-list', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(&$this, 'getUserMessageslist'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
- register_rest_route($this->restapiurl.'/'.$this->restapiversion , 'load-guppy-chat' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'load-guppy-chat', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(&$this, 'getGuppyChat'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
-
- register_rest_route($this->restapiurl.'/'.$this->restapiversion , 'send-guppy-message' , array(
+
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'send-guppy-message', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array(&$this, 'sendMessage'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
- register_rest_route($this->restapiurl.'/'.$this->restapiversion , 'delete-guppy-message' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'delete-guppy-message', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array(&$this, 'deleteGuppyMessage'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
- register_rest_route($this->restapiurl.'/'.$this->restapiversion , 'update-guppy-message' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'update-guppy-message', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array(&$this, 'updateGuppyMessage'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
-
- register_rest_route($this->restapiurl.'/'.$this->restapiversion , 'update-user-status' , array(
+
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'update-user-status', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array(&$this, 'updateGuppyUserStatus'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
- register_rest_route($this->restapiurl.'/'.$this->restapiversion , 'clear-guppy-chat' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'clear-guppy-chat', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array(&$this, 'clearGuppyChat'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
- register_rest_route($this->restapiurl.'/'.$this->restapiversion , 'mute-guppy-notifications' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'mute-guppy-notifications', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array(&$this, 'muteGuppyNotification'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
- register_rest_route($this->restapiurl.'/'.$this->restapiversion , 'get-messenger-chat-info' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'get-messenger-chat-info', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(&$this, 'messengerChatInfo'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
- register_rest_route($this->restapiurl.'/'. $this->restapiversion , 'register-guppy-account' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'register-guppy-account', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array(&$this, 'registerGuppyGuestAccount'),
'args' => array(),
- 'permission_callback' => '__return_true',
+ 'permission_callback' => '__return_true',
));
-
- register_rest_route($this->restapiurl.'/'. $this->restapiversion , 'load-guppy-support-users' , array(
+
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'load-guppy-support-users', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(&$this, 'getGuppySupportUsers'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
- register_rest_route($this->restapiurl.'/'. $this->restapiversion , 'load-guppy-support-messages-list' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'load-guppy-support-messages-list', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(&$this, 'getGuppySupportMessagesList'),
'args' => array(),
- 'permission_callback' => [&$this, 'guppyAuthentications'],
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
- register_rest_route($this->restapiurl.'/'.$this->restapiversion , 'load-guppy-whatsapp-users' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'load-guppy-whatsapp-users', array(
'methods' => WP_REST_Server::READABLE,
'callback' => array(&$this, 'getwhatsappUserList'),
'args' => array(),
- 'permission_callback' => '__return_true',
+ 'permission_callback' => '__return_true',
));
- register_rest_route($this->restapiurl.'/'.$this->restapiversion , 'user-typing' , array(
+ register_rest_route($this->restapiurl . '/' . $this->restapiversion, 'user-typing', array(
'methods' => WP_REST_Server::CREATABLE,
'callback' => array(&$this, 'pusherTypeIndicator'),
'args' => array(),
- 'permission_callback' => '__return_true',
+ 'permission_callback' => [&$this, 'guppyAuthentications'],
));
});
}
@@ -375,26 +386,27 @@
* Register Guppy Constants
*
* @since 1.0.0
- */
- public function registerGuppyConstant(){
-
+ */
+ public function registerGuppyConstant()
+ {
+
$loginedUser = '';
$userType = '';
- if(is_user_logged_in()){
+ if (is_user_logged_in()) {
global $current_user, $post;
$loginedUser = $current_user->ID;
$postId = !empty($post->ID) ? $post->ID : 0;
$userType = 1;
- }elseif(isset($_COOKIE['guppy_guest_account']) ){
+ } elseif (isset($_COOKIE['guppy_guest_account'])) {
$session = explode('|', ($_COOKIE['guppy_guest_account']));
- $loginedUser = !empty($session[1]) ? $session[1] : '';
+ $loginedUser = !empty($session[1]) ? $session[1] : '';
$userType = 0;
}
$isSupportMember = false;
$userData = get_userdata($loginedUser);
- if(!empty($userData)){
+ if (!empty($userData)) {
$isSupportMember = get_user_meta($loginedUser, 'is_guppy_admin', true);
- if(!empty($isSupportMember) && $isSupportMember == 1){
+ if (!empty($isSupportMember) && $isSupportMember == 1) {
$isSupportMember = true;
}
}
@@ -402,13 +414,13 @@
$token = $this->getGuppyAuthToken($loginedUser);
$authToken = $token['authToken'];
wp_localize_script($this->plugin_name, 'wpguppy_scripts_vars', array(
- 'restapiurl' => get_rest_url( null, $this->restapiurl.'/'.$this->restapiversion.'/') ,
+ 'restapiurl' => get_rest_url(null, $this->restapiurl . '/' . $this->restapiversion . '/'),
'rest_nonce' => wp_create_nonce('wp_rest'),
- 'showRec' => $this->showRec,
+ 'showRec' => $this->showRec,
'isSupportMember' => $isSupportMember,
'userType' => $userType,
'userId' => $loginedUser,
- 'logoutUrl' => esc_url(wp_logout_url(home_url('/'))),
+ 'logoutUrl' => esc_url(wp_logout_url(home_url('/'))),
'friendListStatusText' => $settings['textSetting'],
'chatSetting' => $settings['chatSetting'],
'authToken' => $authToken,
@@ -419,13 +431,14 @@
* Get guppy auth token
*
* @since 1.0.0
- */
- public function getGuppyAuthToken($loginedUser , $ismobApp = false){
+ */
+ public function getGuppyAuthToken($loginedUser, $ismobApp = false)
+ {
$jwt = array();
$issuedAt = time();
$notBefore = $issuedAt + 10;
$expire = $issuedAt + (DAY_IN_SECONDS * 1);
- if($ismobApp){
+ if ($ismobApp) {
$expire = $issuedAt + (DAY_IN_SECONDS * 60);
}
$token = array(
@@ -439,7 +452,7 @@
),
),
);
- $authToken = JWT::encode($token, $this->secretKey , 'HS256');
+ $authToken = JWT::encode($token, $this->secretKey, 'HS256');
$jwt['authToken'] = $authToken;
return $jwt;
}
@@ -448,19 +461,20 @@
* Get guppy settings
*
* @since 1.0.0
- */
- public function getGuppySettings($data = null){
+ */
+ public function getGuppySettings($data = null)
+ {
$settings = $json = array();
$loginedUser = 0;
- if(is_user_logged_in()){
+ if (is_user_logged_in()) {
global $current_user;
$loginedUser = $current_user->ID;
}
- if($data){
+ if ($data) {
$params = !empty($data->get_params()) ? $data->get_params() : '';
- $loginedUser = !empty($params['userId']) ? $params['userId'] : 0;
+ $loginedUser = !empty($params['userId']) ? $params['userId'] : 0;
}
- $default_bell_url = WP_GUPPY_LITE_DIRECTORY_URI.'public/media/notification-bell.wav';
+ $default_bell_url = WP_GUPPY_LITE_DIRECTORY_URI . 'public/media/notification-bell.wav';
$messangerPageId = !empty($this->guppySetting['messanger_page_id']) ? $this->guppySetting['messanger_page_id'] : 0;
$notificationBellUrl = !empty($this->guppySetting['notification_bell_url']) ? $this->guppySetting['notification_bell_url'] : $default_bell_url;
$primaryColor = !empty($this->guppySetting['primary_color']) ? $this->guppySetting['primary_color'] : '#FF7300';
@@ -483,54 +497,54 @@
$deleteMessageOption = !empty($this->guppySetting['delete_message']) && $this->guppySetting['delete_message'] == 'disable' ? false : true;
$clearChatOption = !empty($this->guppySetting['clear_chat']) && $this->guppySetting['clear_chat'] == 'disable' ? false : true;
$hideAccSettings = !empty($this->guppySetting['hide_acc_settings']) && $this->guppySetting['hide_acc_settings'] == 'yes' ? true : false;
- $default_translations = wp_list_pluck(apply_filters( 'wpguppy_default_text','' ),'default');
+ $default_translations = wp_list_pluck(apply_filters('wpguppy_default_text', ''), 'default');
$autoInvite = false;
-
+
$roles = $this->getUserRoles($loginedUser);
-
- if(!empty($roles) && $roles['autoInvite']){
+
+ if (!empty($roles) && $roles['autoInvite']) {
$autoInvite = true;
}
- foreach($default_translations as $key=> &$value){
- if(!empty($translations[$key])){
+ foreach ($default_translations as $key => &$value) {
+ if (!empty($translations[$key])) {
$default_translations[$key] = $translations[$key];
}
}
-
-
+
+
$chatSetting = array(
'notificationBellUrl' => $notificationBellUrl,
'translations' => $default_translations,
'defaultActiveTab' => $defaultActiveTab,
'enabledTabs' => $enabledTabs,
- 'primaryColor' => $primaryColor,
- 'secondaryColor' => $secondaryColor,
- 'textColor' => $textColor,
- 'autoInvite' => $autoInvite,
- 'realTimeOption' => $realTimeOption,
- 'pusherEnable' => $pusherEnable,
- 'socketEnable' => $socketEnable,
+ 'primaryColor' => $primaryColor,
+ 'secondaryColor' => $secondaryColor,
+ 'textColor' => $textColor,
+ 'autoInvite' => $autoInvite,
+ 'realTimeOption' => $realTimeOption,
+ 'pusherEnable' => $pusherEnable,
+ 'socketEnable' => $socketEnable,
'floatingWindowEnable' => $floatingWindowEnable,
- 'whatsappSupportEnable' => $whatsappSupportEnable,
+ 'whatsappSupportEnable' => $whatsappSupportEnable,
'floatingMessenger' => $floatingMessenger,
- 'pusherKey' => $appKey,
- 'pusherCluster' => $appCluster,
- 'socketHost' => $socketHost,
- 'socketPort' => $socketPort,
+ 'pusherKey' => $appKey,
+ 'pusherCluster' => $appCluster,
+ 'socketHost' => $socketHost,
+ 'socketPort' => $socketPort,
'isRtl' => is_rtl(),
- 'typingIcon' => WP_GUPPY_LITE_DIRECTORY_URI.'public/images/typing.gif',
- 'videoThumbnail' => WP_GUPPY_LITE_DIRECTORY_URI.'public/images/video-thumbnail.jpg',
- 'floatingIcon' => !empty($floatingIcon) ? $floatingIcon : WP_GUPPY_LITE_DIRECTORY_URI.'public/images/floating-logo.gif',
- 'messangerPage' => apply_filters('wpguppy_messenger_link',get_the_permalink($messangerPageId)),
+ 'typingIcon' => WP_GUPPY_LITE_DIRECTORY_URI . 'public/images/typing.gif',
+ 'videoThumbnail' => WP_GUPPY_LITE_DIRECTORY_URI . 'public/images/video-thumbnail.jpg',
+ 'floatingIcon' => !empty($floatingIcon) ? $floatingIcon : WP_GUPPY_LITE_DIRECTORY_URI . 'public/images/floating-logo.gif',
+ 'messangerPage' => apply_filters('wpguppy_messenger_link', get_the_permalink($messangerPageId)),
'deleteMessageOption' => $deleteMessageOption,
- 'messangerPageSeprator' => apply_filters('wpguppy_messenger_link_seprator','?'),
+ 'messangerPageSeprator' => apply_filters('wpguppy_messenger_link_seprator', '?'),
'clearChatOption' => $clearChatOption,
'hideAccSettings' => $hideAccSettings,
'isMobileDevice' => wp_is_mobile(),
);
-
- $textSetting = array(
- 'sent' => esc_html__( $default_translations['sent'], 'wpguppy-lite'),
+
+ $textSetting = array(
+ 'sent' => esc_html__($default_translations['sent'], 'wpguppy-lite'),
'invite' => esc_html__($default_translations['invite'], 'wpguppy-lite'),
'blocked' => esc_html__($default_translations['blocked'], 'wpguppy-lite'),
'respond' => esc_html__($default_translations['respond_invite'], 'wpguppy-lite'),
@@ -539,10 +553,10 @@
$settings['textSetting'] = $textSetting;
$settings['chatSetting'] = $chatSetting;
- if($data){
- $json['settings'] = $settings;
+ if ($data) {
+ $json['settings'] = $settings;
return new WP_REST_Response($json, 200);
- }else{
+ } else {
return $settings;
}
}
@@ -551,19 +565,20 @@
* Get guppy user Roles
*
* @since 1.0.0
- */
- public function getUserRoles($userId) {
+ */
+ public function getUserRoles($userId)
+ {
$roles = array(
'autoInvite' => false,
);
- if(!empty($userId)){
+ if (!empty($userId)) {
$user_meta = get_userdata($userId);
$user_roles = $user_meta->roles;
$autoInvitesRoles = !empty($this->guppySetting['auto_invite']) ? $this->guppySetting['auto_invite'] : array();
$autoInvite = false;
- if(!empty($user_roles)){
- foreach($user_roles as $single){
- if(in_array($single, $autoInvitesRoles)){
+ if (!empty($user_roles)) {
+ foreach ($user_roles as $single) {
+ if (in_array($single, $autoInvitesRoles)) {
$autoInvite = true;
}
}
@@ -574,85 +589,88 @@
}
/**
- * Login user for guppy mobile application
- *
- * @param WP_REST_Request $request Full data about the request.
- * @return WP_Error|WP_REST_Request
- */
- public function userAuth($data) {
-
+ * Login user for guppy mobile application
+ *
+ * @param WP_REST_Request $request Full data about the request.
+ * @return WP_Error|WP_REST_Request
+ */
+ public function userAuth($data)
+ {
+
$headers = $data->get_headers();
$params = !empty($data->get_params()) ? $data->get_params() : '';
$json = $userInfo = array();
- $username = !empty( $params['username'] ) ? sanitize_text_field($params['username']) : '';
- $userpassword = !empty( $params['userpassword'] ) ? sanitize_text_field($params['userpassword']) : '';
- $isMobApp = !empty( $params['isMobApp'] ) ? intval($params['isMobApp']) : 0;
- if (!empty($username) && !empty($userpassword)) {
-
+ $username = !empty($params['username']) ? sanitize_text_field($params['username']) : '';
+ $userpassword = !empty($params['userpassword']) ? sanitize_text_field($params['userpassword']) : '';
+ $isMobApp = !empty($params['isMobApp']) ? intval($params['isMobApp']) : 0;
+ if (!empty($username) && !empty($userpassword)) {
+
$creds = array(
- 'user_login' => $username,
- 'user_password' => $userpassword,
- 'remember' => true
- );
-
- $user = wp_signon($creds, false);
-
+ 'user_login' => $username,
+ 'user_password' => $userpassword,
+ 'remember' => true
+ );
+
+ $user = wp_signon($creds, false);
+
if (is_wp_error($user)) {
- $json['type'] = 'error';
- $json['message'] = esc_html__('user name or password is not correct', 'wpguppy-lite');
+ $json['type'] = 'error';
+ $json['message'] = esc_html__('user name or password is not correct', 'wpguppy-lite');
return new WP_REST_Response($json, 203);
- } else {
-
+ } else {
+
unset($user->allcaps);
unset($user->filter);
- $where = "user_id=".$user->data->ID;
- $fetchResults = $this->guppyModel->getData('*','wpguppy_users',$where );
-
- if(!empty($fetchResults)){
+ $where = "user_id=" . $user->data->ID;
+ $fetchResults = $this->guppyModel->getData('*', 'wpguppy_users', $where);
+
+ if (!empty($fetchResults)) {
$info = $fetchResults[0];
$userInfo['userId'] = $user->data->ID;
$userInfo['userName'] = $info['user_name'];
$userInfo['userEmail'] = $info['user_email'];
$userInfo['userPhone'] = $info['user_phone'];
- }else{
+ } else {
$userInfo['userId'] = $user->data->ID;
- $userInfo['userName'] = $this->guppyModel->getUserInfoData('username', $user->data->ID , array());
+ $userInfo['userName'] = $this->guppyModel->getUserInfoData('username', $user->data->ID, array());
$userInfo['phoneNo'] = $this->guppyModel->getUserInfoData('userphone', $user->data->ID, array());
$userInfo['email'] = $this->guppyModel->getUserInfoData('useremail', $user->data->ID, array());
}
$token = $this->getGuppyAuthToken($user->data->ID, true);
- $authToken = !empty( $token['authToken'] ) ? $token['authToken'] : '';
- $refreshToken = !empty( $token['refreshToken'] ) ? $token['refreshToken'] : '';
+ $authToken = !empty($token['authToken']) ? $token['authToken'] : '';
+ $refreshToken = !empty($token['refreshToken']) ? $token['refreshToken'] : '';
update_user_meta($user->data->ID, 'wpguppy_app_auth_token', $authToken);
$json['type'] = 'success';
$json['message'] = esc_html__('You are logged in', 'wpguppy-lite');
$json['userInfo'] = $userInfo;
$json['authToken'] = $authToken;
$json['refreshToken'] = $refreshToken;
-
+
return new WP_REST_Response($json, 200);
- }
- }else{
+ }
+ } else {
$json['type'] = 'error';
$json['message'] = esc_html__('user name and password are required fields.', 'wpguppy-lite');
return new WP_REST_Response($json, 203);
}
- }
+ }
/**
- * Authorize Pusher Guppy Channel
- *
- * @param WP_REST_Request $request Full data about the request.
- * @return WP_Error|WP_REST_Request
- */
- public function guppyChannelAuthorize($data){
+ * Authorize Pusher Guppy Channel
+ *
+ * @param WP_REST_Request $request Full data about the request.
+ * @return WP_Error|WP_REST_Request
+ */
+ public function guppyChannelAuthorize($data)
+ {
$params = !empty($data->get_params()) ? $data->get_params() : '';
- $socketId = ! empty( $params['socket_id'] ) ? $params['socket_id'] : 0;
- $channelName = ! empty( $params['channel_name'] ) ? $params['channel_name'] : '';
- if($this->pusher){
- wp_send_json(json_decode( $this->pusher->socket_auth($channelName,$socketId)));
+ $socketId = ! empty($params['socket_id']) ? $params['socket_id'] : 0;
+ $channelName = ! empty($params['channel_name']) ? $params['channel_name'] : '';
+
+ if ($this->pusher) {
+ wp_send_json(json_decode($this->pusher->socket_auth($channelName, $socketId)));
}
}
@@ -666,58 +684,60 @@
* @return WP_Error|WP_REST_Request Returns either a WP_Error on failure or a WP_REST_Request on success.
*/
- public function guppyAuthentications($data) {
+ public function guppyAuthentications($data)
+ {
$headers = $data->get_headers();
$params = $data->get_params() ?: [];
$authToken = $headers['authorization'][0] ?? '';
$params['userId'] = isset($params['userId']) ? $params['userId'] : 0;
// Helper function to set error response
- $setError = function($code, $message) {
+ $setError = function ($code, $message) {
$json = [
'type' => 'error',
'message_desc' => $message,
- 'status'=> $code
+ 'status' => $code
];
- return new WP_Error('invalid_token', __('Authentication failed', 'wpguppy-lite' ), $json);
+ return new WP_Error('invalid_token', __('Authentication failed', 'wpguppy-lite'), $json);
};
-
+
// Check if the user is authenticated via JWT token
- if (empty($authToken) || sscanf($authToken, 'Bearer %s', $token) !== 1 ){
+ if (empty($authToken) || sscanf($authToken, 'Bearer %s', $token) !== 1) {
$code = 401;
$message = esc_html__('Authorization token does not found!', 'wpguppy-lite');
return $setError($code, $message);
}
-
+
try {
JWT::$leeway = 60;
$decodedToken = JWT::decode($token, new Key($this->secretKey, 'HS256'));
$now = time();
- if ($decodedToken->iss !== get_bloginfo('url') ||
- !isset($decodedToken?->data?->user?->id) ||
- (string) $decodedToken->data->user->id !== (string) $params['userId'] ||
- $decodedToken->exp < $now) {
- $code = 401;
- $message = esc_html__('Authorization token does not found!', 'wpguppy-lite');
+ if (
+ $decodedToken->iss !== get_bloginfo('url') ||
+ !isset($decodedToken?->data?->user?->id) ||
+ (string) $decodedToken->data->user->id !== (string) $params['userId'] ||
+ $decodedToken->exp < $now
+ ) {
+ $code = 401;
+ $message = esc_html__('Authorization token does not found!', 'wpguppy-lite');
return $setError($code, $message);
}
-
+
// After validating the token, manually set the logged-in user
$user_id = $decodedToken?->data?->user?->id ?? null;
$user = get_user_by('id', $user_id);
-
+
if (empty($user) && $params['userType'] == 1) {
$code = 401;
$message = esc_html__('User not found or invalid user!', 'wpguppy-lite');
return $setError($code, $message);
}
-
} catch (Exception $e) {
$code = 401;
return $setError($code, $e->getMessage());
}
-
+
// At this point, the user is authenticated, so we can proceed with the rest of the logic.
// Validate userId and userType
if (empty($params['userId']) || (isset($params['userType']) && $params['userType'] == 1 && empty(get_userdata($params['userId'])))) {
@@ -725,7 +745,7 @@
$message = esc_html__('You are not allowed to perform this action!', 'wpguppy-lite');
return $setError($code, $message);
}
-
+
$this->userId = $params['userId'];
return true;
}
@@ -734,25 +754,27 @@
* Get timeFormat
*
* @since 1.0.0
- */
- public function getTimeFormat($time){
- $time_offset = (float) get_option( 'gmt_offset' );
- $seconds = intval( $time_offset * HOUR_IN_SECONDS );
- $timestamp = strtotime( $time ) + $seconds;
- $timeFormat = !empty($time) ? human_time_diff( $timestamp,current_time( 'timestamp' ) ).' '.esc_html__('ago','wpguppy-lite') : '';
+ */
+ public function getTimeFormat($time)
+ {
+ $time_offset = (float) get_option('gmt_offset');
+ $seconds = intval($time_offset * HOUR_IN_SECONDS);
+ $timestamp = strtotime($time) + $seconds;
+ $timeFormat = !empty($time) ? human_time_diff($timestamp, current_time('timestamp')) . ' ' . esc_html__('ago', 'wpguppy-lite') : '';
return $timeFormat;
}
-
+
/**
* Get guppy whatsappUser
*
* @since 1.0.0
- */
- public function getwhatsappUserList($data){
+ */
+ public function getwhatsappUserList($data)
+ {
$headers = $data->get_headers();
$params = !empty($data->get_params()) ? $data->get_params() : '';
$json = $userList = array();
- $offset = !empty($params['offset']) ? intval($params['offset']) : 0;
+ $offset = !empty($params['offset']) ? intval($params['offset']) : 0;
$searchQuery = !empty($params['search']) ? esc_sql(sanitize_text_field($params['search'])) : '';
$query_args = array(
'fields' => array('id'),
@@ -760,8 +782,8 @@
'order' => 'DESC',
'offset' => $offset,
'number' => $this->showRec,
- 'meta_query' => array(
- 'relation' => 'AND',
+ 'meta_query' => array(
+ 'relation' => 'AND',
array(
'key' => 'is_guppy_whatsapp_user',
'value' => '1',
@@ -769,13 +791,13 @@
)
)
);
- if( !empty($searchQuery) ){
- $query_args['search'] = '*'.$searchQuery.'*';
+ if (!empty($searchQuery)) {
+ $query_args['search'] = '*' . $searchQuery . '*';
}
- $allusers = get_users( $query_args );
+ $allusers = get_users($query_args);
- if(!empty($allusers)){
- foreach($allusers as $user){
+ if (!empty($allusers)) {
+ foreach ($allusers as $user) {
$key = $this->guppyModel->getChatKey('4', $user->id);
$guppyWhatsappInfo = get_user_meta($user->id, 'guppy_whatsapp_info', true);
$userDesignation = !empty($guppyWhatsappInfo['user_designation']) ? $guppyWhatsappInfo['user_designation'] : '';
@@ -784,7 +806,7 @@
$userOfflineMessage = !empty($guppyWhatsappInfo['user_offline_message']) ? $guppyWhatsappInfo['user_offline_message'] : '';
$userAvailability = !empty($guppyWhatsappInfo['user_availability']) ? $guppyWhatsappInfo['user_availability'] : array();
$usertimeZone = !empty($guppyWhatsappInfo['user_timezone']) ? $guppyWhatsappInfo['user_timezone'] : '';
-
+
$userData = $this->guppyModel->getUserInfo('1', $user->id);
$userName = $userData['userName'];
$userAvatar = $userData['userAvatar'];
@@ -802,45 +824,45 @@
}
}
$json['type'] = 'success';
- $json['userList'] = (Object)$userList;
+ $json['userList'] = (object)$userList;
$json['status'] = 200;
- return new WP_REST_Response($json , $json['status']);
+ return new WP_REST_Response($json, $json['status']);
}
/**
* send guppy invite
*
* @since 1.0.0
- */
- public function sendGuppyInvite( $data )
+ */
+ public function sendGuppyInvite($data)
{
$params = !empty($data->get_params()) ? $data->get_params() : '';
$json = $friendData = array();
- $loginedUser = $this->userId;
- $sendTo = !empty( $params['sendTo'] ) ? intval($params['sendTo']) : 0;
- $startChat = !empty( $params['startChat'] ) ? intval($params['startChat']) : 0;
+ $loginedUser = $this->userId;
+ $sendTo = !empty($params['sendTo']) ? intval($params['sendTo']) : 0;
+ $startChat = !empty($params['startChat']) ? intval($params['startChat']) : 0;
$autoInvite = false;
$loginUserRoles = $this->getUserRoles($loginedUser);
- if($startChat == 1){
- if(!empty($loginUserRoles) && $loginUserRoles['autoInvite']){
+ if ($startChat == 1) {
+ if (!empty($loginUserRoles) && $loginUserRoles['autoInvite']) {
$autoInvite = true;
- }else{
+ } else {
$json['type'] = 'error';
$json['message_desc'] = esc_html__('You are not allowed to perform this action!', 'wpguppy-lite');
- return new WP_REST_Response($json , 203);
+ return new WP_REST_Response($json, 203);
}
}
- $fetchResults = $this->guppyModel->getGuppyFriend($sendTo,$loginedUser,false);
+ $fetchResults = $this->guppyModel->getGuppyFriend($sendTo, $loginedUser, false);
$response = false;
- if( empty(get_userdata($sendTo)) || $loginedUser == $sendTo){
+ if (empty(get_userdata($sendTo)) || $loginedUser == $sendTo) {
$json['type'] = 'error';
$json['message_desc'] = esc_html__('You are not allowed to perform this action!', 'wpguppy-lite');
- return new WP_REST_Response($json , 203);
- } elseif(!empty( $fetchResults) && ($fetchResults['friend_status'] == '1' || $fetchResults['friend_status'] == '3')){
+ return new WP_REST_Response($json, 203);
+ } elseif (!empty($fetchResults) && ($fetchResults['friend_status'] == '1' || $fetchResults['friend_status'] == '3')) {
$messageData = $messagelistData = array();
// get receiver user info
$receiverUserName = $receiverUserAvatar = '';
$userData = $this->getUserInfo('1', $sendTo);
- if(!empty($userData)){
+ if (!empty($userData)) {
$receiverUserAvatar = $userData['userAvatar'];
$receiverUserName = $userData['userName'];
}
@@ -849,7 +871,7 @@
$friendData = array(
'userId' => $sendTo,
'chatType' => 1,
- 'chatId' => $this->getChatKey('1',$sendTo),
+ 'chatId' => $this->getChatKey('1', $sendTo),
'friendStatus' => $fetchResults['friend_status'],
'userName' => $receiverUserName,
'userAvatar' => $receiverUserAvatar,
@@ -859,7 +881,7 @@
);
$fetchResults = $this->guppyModel->getUserLatestMessage($loginedUser, $sendTo); // senderId, receiverId
$messageResult = ! empty($fetchResults) ? $fetchResults[0] : array();
-
+
// check chat is cleard or not
$chatClearTime = '';
$clearChat = false;
@@ -870,8 +892,8 @@
$filterData['actionType'] = '0';
$filterData['chatType'] = $chatType;
$chatActions = $this->getGuppyChatAction($filterData);
-
- if(!empty($chatActions)){
+
+ if (!empty($chatActions)) {
$chatClearTime = $chatActions['chatClearTime'];
}
@@ -881,50 +903,49 @@
$chatNotify['userId'] = $sendTo;
$chatNotify['chatType'] = $chatType;
$muteNotification = $this->getGuppyChatAction($chatNotify);
-
- if(!empty($muteNotification)){
+
+ if (!empty($muteNotification)) {
$muteNotification = true;
- }else{
+ } else {
$muteNotification = false;
}
-
+
$message = $messageResult['message'];
- if(!empty($chatClearTime) && strtotime($chatClearTime) > strtotime($messageResult['message_sent_time'])){
+ if (!empty($chatClearTime) && strtotime($chatClearTime) > strtotime($messageResult['message_sent_time'])) {
$clearChat = true;
$message = '';
}
-
+
$messagelistData['messageId'] = $messageResult['id'];
- $messagelistData['message'] = $message;
- $messagelistData['timeStamp'] = $messageResult['timestamp'];
+ $messagelistData['message'] = $message;
+ $messagelistData['timeStamp'] = $messageResult['timestamp'];
$messagelistData['messageType'] = $messageResult['message_type'];
$messagelistData['chatType'] = $messageResult['chat_type'];
$messagelistData['isSender'] = $messageResult['sender_id'] == $loginedUser ? true : false;
$messagelistData['messageStatus'] = $messageResult['message_status'];
$messagelistData['userName'] = $receiverUserName;
$messagelistData['userAvatar'] = $receiverUserAvatar;
- $messagelistData['chatId'] = $this->getChatKey('1',$sendTo);
+ $messagelistData['chatId'] = $this->getChatKey('1', $sendTo);
$messagelistData['blockedId'] = !empty($userStatus['blockedId']) ? $userStatus['blockedId'] : '';
$messagelistData['clearChat'] = $clearChat;
$messagelistData['isBlocked'] = !empty($userStatus['isBlocked']) ? $userStatus['isBlocked'] : false;
$messagelistData['isOnline'] = !empty($userStatus['isOnline']) ? $userStatus['isOnline'] : false;
$messagelistData['UnreadCount'] = 0;
$messagelistData['muteNotification'] = $muteNotification;
-
+
$json['autoInvite'] = $autoInvite;
$json['messagelistData'] = $messagelistData;
$json['friendData'] = $friendData;
$json['resendRequest'] = true;
$json['type'] = 'success';
$json['status'] = 200;
- return new WP_REST_Response($json , $json['status']);
+ return new WP_REST_Response($json, $json['status']);
+ } elseif (!empty($fetchResults) && ($fetchResults['friend_status'] == '2' || $fetchResults['friend_status'] == '0')) {
- }elseif(!empty( $fetchResults) && ($fetchResults['friend_status'] == '2' || $fetchResults['friend_status'] == '0')){
-
- if($startChat == 1 && $autoInvite){
+ if ($startChat == 1 && $autoInvite) {
$current_date = date('Y-m-d H:i:s');
$friend_status = 1;
- }else{
+ } else {
$current_date = $fetchResults['friend_created_date'];
$friend_status = 0;
}
@@ -940,7 +961,7 @@
'send_to' => $sendTo,
);
- if($fetchResults['send_by'] != $loginedUser){
+ if ($fetchResults['send_by'] != $loginedUser) {
$where = array(
'send_by' => $sendTo,
'send_to' => $loginedUser,
@@ -953,13 +974,13 @@
'send_to' => $sendTo,
);
}
-
- $response = $this->guppyModel->updateData( 'wpguppy_friend_list' , $data, $where);
- }elseif(empty($fetchResults)){
- if($startChat == 1 && $autoInvite){
+
+ $response = $this->guppyModel->updateData('wpguppy_friend_list', $data, $where);
+ } elseif (empty($fetchResults)) {
+ if ($startChat == 1 && $autoInvite) {
$current_date = date('Y-m-d H:i:s');
$friend_status = 1;
- }else{
+ } else {
$current_date = NULL;
$friend_status = 0;
}
@@ -969,32 +990,32 @@
'friend_created_date' => $current_date,
'friend_status' => $friend_status,
);
-
- $response = $this->guppyModel->insertData('wpguppy_friend_list' , $data);
+
+ $response = $this->guppyModel->insertData('wpguppy_friend_list', $data);
}
-
+
$inviteStatus = esc_html__('Sent', 'wpguppy-lite');
- if ( $response) {
- if($startChat == 1 && $autoInvite){
+ if ($response) {
+ if ($startChat == 1 && $autoInvite) {
$isOnline = wpguppy_UserOnline($sendTo);
// get receiver user info
$receiverUserName = $receiverUserAvatar = '';
$userData = $this->getUserInfo('1', $sendTo);
- if(!empty($userData)){
+ if (!empty($userData)) {
$receiverUserAvatar = $userData['userAvatar'];
$receiverUserName = $userData['userName'];
}
// get sender user info
$senderUserName = $senderUserAvatar = '';
$senderUserData = $this->getUserInfo(1, $loginedUser);
- if(!empty($senderUserData)){
+ if (!empty($senderUserData)) {
$senderUserName = $senderUserData['userName'];
$senderUserAvatar = $senderUserData['userAvatar'];
}
$friendData = array(
'userId' => $sendTo,
'chatType' => 1,
- 'chatId' => $this->getChatKey('1',$sendTo),
+ 'chatId' => $this->getChatKey('1', $sendTo),
'friendStatus' => 1,
'userName' => $receiverUserName,
'userAvatar' => $receiverUserAvatar,
@@ -1005,47 +1026,47 @@
$messageData = $messagelistData = array();
$messageSentTime = date('Y-m-d H:i:s');
$timestamp = strtotime($messageSentTime);
-
- $messageData['sender_id'] = $loginedUser;
- $messageData['receiver_id'] = $sendTo;
- $messageData['user_type'] = 1;
- $messageData['chat_type'] = 1;
+
+ $messageData['sender_id'] = $loginedUser;
+ $messageData['receiver_id'] = $sendTo;
+ $messageData['user_type'] = 1;
+ $messageData['chat_type'] = 1;
$messageData['message_type'] = 4;
- $messageData['timestamp'] = $timestamp;
+ $messageData['timestamp'] = $timestamp;
$messageData['message_sent_time'] = $messageSentTime;
$data = array();
$data['type'] = 1;
- $messageData['message'] = serialize($data);
- $messageId = $this->guppyModel->insertData('wpguppy_message',$messageData);
-
- $messagelistData['messageId'] = $messageId;
- $messagelistData['message'] = $data;
- $messagelistData['timeStamp'] = $messageData['timestamp'];
+ $messageData['message'] = serialize($data);
+ $messageId = $this->guppyModel->insertData('wpguppy_message', $messageData);
+
+ $messagelistData['messageId'] = $messageId;
+ $messagelistData['message'] = $data;
+ $messagelistData['timeStamp'] = $messageData['timestamp'];
$messagelistData['messageType'] = 4;
$messagelistData['chatType'] = 1;
$messagelistData['isSender'] = false;
$messagelistData['messageStatus'] = '0';
$messagelistData['userName'] = $senderUserName;
$messagelistData['userAvatar'] = $senderUserAvatar;
- $messagelistData['chatId'] = $this->getChatKey('1',$loginedUser);
+ $messagelistData['chatId'] = $this->getChatKey('1', $loginedUser);
$messagelistData['blockedId'] = false;
$messagelistData['isBlocked'] = false;
$messagelistData['isOnline'] = $isOnline;
$messagelistData['UnreadCount'] = 0;
$messagelistData['muteNotification'] = false;
$messagelistData['isStartChat'] = true;
-
+
$chatData = array(
'chatType' => 1,
- 'chatId' => $this->getChatKey('1',$sendTo),
- 'messageId' => $messageId,
- 'message' => $data,
- 'timeStamp' => $messageData['timestamp'],
+ 'chatId' => $this->getChatKey('1', $sendTo),
+ 'messageId' => $messageId,
+ 'message' => $data,
+ 'timeStamp' => $messageData['timestamp'],
'messageType' => 4,
'userType' => 1,
- 'messageStatus' => '0',
- 'replyMessage' => NULL,
- 'isOnline' => $isOnline,
+ 'messageStatus' => '0',
+ 'replyMessage' => NULL,
+ 'isOnline' => $isOnline,
'metaData' => false,
'userName' => $senderUserName,
'userAvatar' => $senderUserAvatar,
@@ -1055,12 +1076,12 @@
$json['messagelistData'] = $messagelistData;
$json['userName'] = $receiverUserName;
$json['userAvatar'] = $receiverUserAvatar;
-
- if($this->pusher){
+
+ if ($this->pusher) {
$batchRequests = array();
// send to receiver
$pusherData = array(
- 'chatId' => $this->getChatKey('1',$loginedUser),
+ 'chatId' => $this->getChatKey('1', $loginedUser),
'chatData' => $chatData,
'chatType' => 1,
'messagelistData' => $messagelistData
@@ -1077,9 +1098,9 @@
$messagelistData['userName'] = $receiverUserName;
$messagelistData['userAvatar'] = $receiverUserAvatar;
$messagelistData['UnreadCount'] = 0;
- $messagelistData['chatId'] = $this->getChatKey('1',$sendTo);
+ $messagelistData['chatId'] = $this->getChatKey('1', $sendTo);
$pusherData = array(
- 'chatId' => $this->getChatKey('1',$sendTo),
+ 'chatId' => $this->getChatKey('1', $sendTo),
'chatType' => 1,
'chatData' => $chatData,
'messagelistData' => $messagelistData,
@@ -1091,7 +1112,7 @@
);
$this->pusher->triggerBatch($batchRequests);
}
- }
+ }
$json['inviteStatus'] = $inviteStatus;
$json['autoInvite'] = $autoInvite;
$json['friendData'] = $friendData;
@@ -1102,15 +1123,16 @@
$json['type'] = 'error';
$json['status'] = 203;
}
- return new WP_REST_Response($json , $json['status']);
+ return new WP_REST_Response($json, $json['status']);
}
/**
* Register guest users
*
* @since 1.0.0
- */
- public function registerGuppyGuestAccount($data){
+ */
+ public function registerGuppyGuestAccount($data)
+ {
$headers = $data->get_headers();
$params = ! empty($data->get_params()) ? $data->get_params() : '';
$authToken = ! empty($headers['authorization'][0]) ? $headers['authorization'][0] : '';
@@ -1123,12 +1145,12 @@
$guestEmail = !empty($params['guestEmail']) ? sanitize_email($params['guestEmail']) : '';
$ipAddress = $_SERVER['REMOTE_ADDR'];
$userAgent = $_SERVER['HTTP_USER_AGENT'];
-
- if(empty($guestName) || empty($guestEmail)){
+
+ if (empty($guestName) || empty($guestEmail)) {
$json['type'] = 'error';
$json['message_desc'] = esc_html__('Please fill the given details', 'wpguppy-lite');
- return new WP_REST_Response($json , 203);
- }else{
+ return new WP_REST_Response($json, 203);
+ } else {
$data = array(
'name' => $guestName,
@@ -1137,8 +1159,8 @@
'user_agent' => $userAgent,
);
- if(!session_id()){
-
+ if (!session_id()) {
+
// long time
$sessionTime = 90 * 24 * 60 * 60;
$sessionName = "guppy_guest_account";
@@ -1147,16 +1169,16 @@
session_start();
$userId = session_id();
- $where = "guest_id='$userId'";
- $fetchResults = $this->guppyModel->getData('guest_id,name','wpguppy_guest_account',$where );
- if(empty($fetchResults)){
+ $where = "guest_id='$userId'";
+ $fetchResults = $this->guppyModel->getData('guest_id,name', 'wpguppy_guest_account', $where);
+ if (empty($fetchResults)) {
$data['guest_id'] = $userId;
- $this->guppyModel->insertData('wpguppy_guest_account' , $data);
+ $this->guppyModel->insertData('wpguppy_guest_account', $data);
}
-
+
$data['userId'] = $userId;
$_SESSION[$sessionName] = $data;
- $cookiesValue = $data['name']."|$userId";
+ $cookiesValue = $data['name'] . "|$userId";
setcookie($sessionName, $cookiesValue, time() + $sessionTime, "/",);
@@ -1165,26 +1187,27 @@
$authToken = $token['authToken'];
session_write_close();
}
-
+
$type = 'success';
$status = 200;
- $json['userId'] = $userId;
- $json['authToken'] = $authToken;
+ $json['userId'] = $userId;
+ $json['authToken'] = $authToken;
}
$json['type'] = $type;
- return new WP_REST_Response($json , $status);
+ return new WP_REST_Response($json, $status);
}
/**
* Get guppy admin users
*
* @since 1.0.0
- */
- public function getGuppySupportUsers($data){
+ */
+ public function getGuppySupportUsers($data)
+ {
$params = !empty($data->get_params()) ? $data->get_params() : '';
- $offset = !empty($params['offset']) ? intval($params['offset']) : 0;
- $searchQuery = !empty($params['search']) ? esc_sql(sanitize_text_field($params['search'])) : '';
- $loginedUser = $this->userId;
+ $offset = !empty($params['offset']) ? intval($params['offset']) : 0;
+ $searchQuery = !empty($params['search']) ? esc_sql(sanitize_text_field($params['search'])) : '';
+ $loginedUser = $this->userId;
$supportUsers = $json = array();
$query_args = array(
'fields' => array('id'),
@@ -1202,19 +1225,19 @@
)
);
- if( !empty($searchQuery) ){
- $query_args['search'] = '*'.$searchQuery.'*';
+ if (!empty($searchQuery)) {
+ $query_args['search'] = '*' . $searchQuery . '*';
}
- $allusers = get_users( $query_args );
+ $allusers = get_users($query_args);
- if(!empty($allusers)){
- foreach($allusers as $user){
+ if (!empty($allusers)) {
+ foreach ($allusers as $user) {
$key = $this->guppyModel->getChatKey(3, $user->id);
$userData = $this->guppyModel->getUserInfo(1, $user->id);
$filterData = array();
$filterData['chatType'] = 3;
$filterData['senderId'] = $user->id;
- $filterData['receiverId'] = $loginedUser;
+ $filterData['receiverId'] = $loginedUser;
$unreadCount = $this->guppyModel->getUnreadCount($filterData);
$supportUsers[$key] = array(
'chatId' => $key,
@@ -1224,41 +1247,42 @@
'UnreadCount' => intval($unreadCount),
'userAvatar' => $userData['userAvatar'],
'isOnline' => wpguppy_UserOnline($user->id),
- );
+ );
}
}
-
+
$json['type'] = 'success';
- $json['supportUsers'] = (Object)$supportUsers;
- return new WP_REST_Response($json , 200);
+ $json['supportUsers'] = (object)$supportUsers;
+ return new WP_REST_Response($json, 200);
}
/**
* Get guppy support messsages
*
* @since 1.0.0
- */
- public function getGuppySupportMessagesList($data){
+ */
+ public function getGuppySupportMessagesList($data)
+ {
$params = !empty($data->get_params()) ? $data->get_params() : '';
$guppyMessageList = $json = array();
- $offset = !empty($params['offset']) ? intval($params['offset']) : 0;
+ $offset = !empty($params['offset']) ? intval($params['offset']) : 0;
$searchQuery = !empty($params['search']) ? esc_sql(sanitize_text_field($params['search'])) : '';
- $loginedUser = $this->userId;
+ $loginedUser = $this->userId;
$isSupportMember = isset($params['isSupportMember']) ? filter_var($params['isSupportMember'], FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) : false;
$fetchResults = $this->guppyModel->getUserAdminSupportMessages($loginedUser, $this->showRec, $offset, $searchQuery, $isSupportMember);
-
- if(!empty($fetchResults)){
- foreach($fetchResults as $result){
+
+ if (!empty($fetchResults)) {
+ foreach ($fetchResults as $result) {
$messageData = array();
- if($result['sp_sender_id'] != $loginedUser){
+ if ($result['sp_sender_id'] != $loginedUser) {
$spReceiverId = $result['sp_sender_id'];
- }else{
- $spReceiverId = $result['sp_rec_id'];
+ } else {
+ $spReceiverId = $result['sp_rec_id'];
}
$isSender = true;
- if($result['sp_sender_id'] != $loginedUser){
- $isSender= false;
+ if ($result['sp_sender_id'] != $loginedUser) {
+ $isSender = false;
}
$message = $result['message'];
@@ -1269,34 +1293,34 @@
$filterData = array();
$filterData['chatType'] = $result['chat_type'];
$filterData['senderId'] = $spReceiverId;
- $filterData['receiverId'] = $loginedUser;
-
+ $filterData['receiverId'] = $loginedUser;
+
$isRegistered = get_userdata($spReceiverId);
$isSupportMember = false;
$verifySupport = get_user_meta($spReceiverId, 'is_guppy_admin', true);
- if(!empty($verifySupport) && $verifySupport == 1){
+ if (!empty($verifySupport) && $verifySupport == 1) {
$isSupportMember = true;
- }else{
+ } else {
$verifySupport = get_user_meta($loginedUser, 'is_guppy_admin', true);
- if(!empty($verifySupport) && $verifySupport == 1){
+ if (!empty($verifySupport) && $verifySupport == 1) {
$isSupportMember = true;
}
}
$userData = $this->guppyModel->getUserInfo($isRegistered ? 1 : 0, $spReceiverId);
- $messageData['userAvatar'] = $userData['userAvatar'];
+ $messageData['userAvatar'] = $userData['userAvatar'];
$messageData['userName'] = $userData['userName'];
$messageData['isOnline'] = wpguppy_UserOnline($spReceiverId);
-
+
$unreadCount = $this->guppyModel->getUnreadCount($filterData);
- if($result['message_status'] == 2 ){
+ if ($result['message_status'] == 2) {
$message = '';
}
-
+
$chatId = $spReceiverId;
- if($message!=''){
- if($messageType == '0'){
- $message = html_entity_decode( stripslashes($message), ENT_QUOTES );
+ if ($message != '') {
+ if ($messageType == '0') {
+ $message = html_entity_decode(stripslashes($message), ENT_QUOTES);
}
}
$key = $this->guppyModel->getChatKey(3, $chatId);
@@ -1307,41 +1331,42 @@
$messageData['isSupportMember'] = $isSupportMember;
$messageData['messageStatus'] = $result['message_status'];
$messageData['chatType'] = intval($result['chat_type']);
- $messageData['UnreadCount'] = intval( $unreadCount );
+ $messageData['UnreadCount'] = intval($unreadCount);
$messageData['timeStamp'] = $timestamp;
$messageData['messageId'] = Intval($result['id']);
$guppyMessageList[$key] = $messageData;
}
}
-
+
$json['type'] = 'success';
- $json['guppyMessageList'] = (Object)$guppyMessageList;
- return new WP_REST_Response($json , 200);
+ $json['guppyMessageList'] = (object)$guppyMessageList;
+ return new WP_REST_Response($json, 200);
}
/**
* update guppy user status
*
* @since 1.0.0
- */
- public function updateGuppyUserStatus( $data ) {
+ */
+ public function updateGuppyUserStatus($data)
+ {
$params = ! empty($data->get_params()) ? $data->get_params() : '';
$json = array();
- $statusType = ! empty( $params['statusType'] ) ? intval($params['statusType'] ) : 0;
- $actionTo = ! empty( $params['actionTo'] ) ? intval($params['actionTo']) : 0 ;
- $loginedUser = $this->userId;
+ $statusType = ! empty($params['statusType']) ? intval($params['statusType']) : 0;
+ $actionTo = ! empty($params['actionTo']) ? intval($params['actionTo']) : 0;