/** * Chat offline shortcode * * @access public * @return string */ function sc_chat_shortcode_offline($atts, $content = '') { // Check if all OPs offline if (!Live_Chat::check_if_any_op_online()) { return $content; } }
/** * Send chat message * * @access public * @return array */ public static function send_chat_msg($params) { // Get user data from session $chat_user_name = $_SESSION['sc_chat']['chat_user_name']; $chat_user_gravatar = $_SESSION['sc_chat']['chat_user_gravatar']; $chat_user_email = $_SESSION['sc_chat']['chat_user_email']; // First check if any OP is online if (!Live_Chat::check_if_any_op_online()) { // Logout user Live_Chat::logout(); // Prepare email data for last message $data = array('f_chat_user_name' => $chat_user_name, 'f_chat_user_email' => $chat_user_email, 'f_chat_user_question' => $params['chat_line'], 'prefix' => '(!) ' . strtoupper(__('User has been sent this message after you disconnected from chat', 'sc_chat')) . ": \r\n\r\n"); // Send email now $email = Live_Chat::send_contact_from($data); if (!empty($email['error'])) { throw new Exception($email['error']); } else { throw new Exception(__("We are offline now. However, your message has been sent to us by email. We will contact you as soon as possible", 'sc_chat')); } } if (empty($chat_user_name)) { throw new Exception(__('You are not logged in', 'sc_chat')); } if (empty($params['chat_line'])) { throw new Exception(__("You haven't entered a chat message", 'sc_chat')); } // If receiver ID empty, make it __OP__ if (current_user_can('chat_with_users') and !empty($params['receiver_ID'])) { $receiver_ID = sanitize_key($params['receiver_ID']); } else { $receiver_ID = '__OP__'; } // sent by visitor // Prepare chat line data $chat = new Chat_line(array('author' => $chat_user_name, 'gravatar' => $chat_user_gravatar, 'visitor_ID' => !empty($params['visitor_ID']) ? $params['visitor_ID'] : null, 'receiver_ID' => $receiver_ID, 'email' => $chat_user_email, 'chat_line' => Live_Chat::sanitize_chat_line($params['chat_line']))); // Save chat message $insert_ID = $chat->save(); return array('status' => 1, 'insert_ID' => $insert_ID); }