Beispiel #1
0
/**
 * 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;
    }
}
Beispiel #2
0
    /**
     * Get chat logs
     *
     * @access public
     * @return array
     */
    public static function get_chat_lines($last_log_ID, $sender = null)
    {
        global $wpdb;
        $chats = array();
        if (!isset($_SESSION['sc_chat']['chat_user_name'])) {
            return array('chats' => $chats);
        }
        $sql_sender = '';
        $last_log_ID = (int) $last_log_ID;
        $username = $_SESSION['sc_chat']['chat_user_name'];
        // Prepare sql with sender
        if (!empty($sender) and current_user_can('chat_with_users')) {
            $sql = $wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'chat_lines 
						WHERE `ID` > %d AND
							( `author` = %s OR `receiver_ID` IN( %s, %s, %s ) )
							ORDER BY `ID` ASC', $last_log_ID, $username, $username, '__OP__', $sender);
            // Prepare sql
        } else {
            if (current_user_can('chat_with_users')) {
                $sql = $wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'chat_lines 
							WHERE `ID` > %d AND
								( `author` = %s OR `receiver_ID` IN( %s, %s ) )
								ORDER BY `ID` ASC', $last_log_ID, $username, $username, '__OP__');
            } else {
                $sql = $wpdb->prepare('SELECT * FROM ' . $wpdb->prefix . 'chat_lines 
							WHERE `ID` > %d AND
								( `author` = %s OR `receiver_ID` = %s )
								ORDER BY `ID` ASC', $last_log_ID, $username, $username);
            }
        }
        // Get new chat lines
        $new_chat_lines = $wpdb->get_results($sql);
        // Update lines data
        foreach ($new_chat_lines as $chat) {
            // Returning the GMT (UTC) time of the chat creation:
            $chat->time = array('hours' => gmdate('H', $chat->chat_date), 'minutes' => gmdate('i', $chat->chat_date));
            // Make urls to links
            $chat->chat_line = sc_chat_make_url_to_link($chat->chat_line);
            // Update gravatar
            $chat->gravatar = Live_Chat::gravatar_from_hash($chat->gravatar);
            $chats[] = $chat;
        }
        return array('chats' => $chats);
    }