function activeListen($runs = 1, $picUpdate = false, $isPost = false)
{
    global $CONFIG, $GROUPS, $INTERNAL, $USER, $ISFORWARD;
    $start = time();
    $USER->Browsers[0]->Typing = isset($_POST[POST_EXTERN_TYPING]);
    while ($runs == 1) {
        isForward();
        processForward();
        if ($runs > 1) {
            getDataSets();
            getData(false, false, false, true);
            $USER->Browsers[0]->LoadChat($CONFIG, null);
            if (isnull($USER->Browsers[0]->Chat)) {
                break;
            }
        }
        if ($USER->Browsers[0]->Chat->Closed) {
            displayQuit();
            return $USER;
        } else {
            if ($USER->Browsers[0]->Chat->Declined) {
                displayDeclined();
                return $USER;
            } else {
                if ($USER->Browsers[0]->Chat->Activated == CHAT_STATUS_WAITING && !$ISFORWARD) {
                    beginnConversation();
                }
            }
        }
        if ($USER->Browsers[0]->Chat->Activated >= CHAT_STATUS_WAITING && !$ISFORWARD) {
            $picUpdate = refreshPicture();
            processTyping();
        }
        if ($runs == 1 && isset($_POST[POST_EXTERN_USER_FILE_UPLOAD_NAME]) && !isset($_POST[POST_EXTERN_USER_FILE_UPLOAD_ERROR]) && !$ISFORWARD) {
            $USER = $USER->Browsers[0]->RequestFileUpload($USER, $_POST[POST_EXTERN_USER_FILE_UPLOAD_NAME]);
        } else {
            if ($runs == 1 && isset($_POST[POST_EXTERN_USER_FILE_UPLOAD_NAME]) && isset($_POST[POST_EXTERN_USER_FILE_UPLOAD_ERROR])) {
                $USER->Browsers[0]->AbortFileUpload($USER, namebase($_POST[POST_EXTERN_USER_FILE_UPLOAD_NAME]), $_POST[POST_EXTERN_USER_FILE_UPLOAD_ERROR]);
            }
        }
        if ($runs++ == 1 && isset($_POST[POST_GLOBAL_SHOUT])) {
            processPosts();
        }
        if ($USER->Browsers[0]->Chat->Activated == CHAT_STATUS_ACTIVE) {
            $isPost = getNewPosts();
            updateRoom($USER->Browsers[0]->Chat->Id, CHAT_STATUS_ACTIVE);
        } else {
            updateRoom($USER->Browsers[0]->Chat->Id, CHAT_STATUS_WAITING);
        }
        if (isset($_POST[POST_GLOBAL_SHOUT]) || isset($_POST[POST_GLOBAL_NO_LONG_POLL]) || $isPost || $ISFORWARD) {
            break;
        } else {
            if (md5($USER->Response) != $_POST[POST_GLOBAL_XMLCLIP_HASH_ALL] || $picUpdate) {
                $_POST[POST_GLOBAL_XMLCLIP_HASH_ALL] = md5($USER->Response);
                $USER->AddFunctionCall("lz_chat_listen_hash('" . md5($USER->Response) . "','" . getId(5) . "');", false);
                break;
            } else {
                $USER->Response = "";
                $wait = max($CONFIG["poll_frequency_clients"] - 1, 1);
                if (time() + $wait < $start + getLongPollRuntime()) {
                    sleep($wait);
                } else {
                    break;
                }
            }
        }
    }
}
function listenXML($runs = 1)
{
    global $CONFIG, $RESPONSE, $INTERNAL;
    processActions();
    if (!SERVERSETUP && !LOGIN && $INTERNAL[CALLER_SYSTEM_ID]->Status == USER_STATUS_OFFLINE) {
        return;
    }
    $start = time();
    while (time() < $start + getLongPollRuntime() || $runs == 1) {
        if ($runs > 1) {
            getDataSets();
            getData(true, true, true, true);
        }
        $RESPONSE->XML = "<listen disabled=\"" . base64_encode(getAvailability() ? "0" : "1") . "\" h=\"<!--gl_all-->\" " . (isset($_POST[POST_INTERN_XMLCLIP_HASH_EXECUTION_TIME]) ? "ex_time=\"<!--execution_time-->\"" : "") . ">\r\n";
        $RESPONSE->Typing = "";
        if ($RESPONSE->Login != null) {
            $RESPONSE->XML .= $RESPONSE->Login;
        }
        buildSystem();
        if ($runs++ == 1) {
            processPosts();
        }
        if (($hash = substr(md5($RESPONSE->Typing), 0, 5)) != @$_POST[POST_INTERN_XMLCLIP_HASH_TYPING] && strlen($RESPONSE->Typing) > 0) {
            $RESPONSE->XML .= "<gl_typ h=\"" . base64_encode($hash) . "\">\r\n" . $RESPONSE->Typing . "</gl_typ>\r\n";
        }
        if (($hash = substr(md5($RESPONSE->Exceptions), 0, 5)) != @$_POST[POST_INTERN_XMLCLIP_HASH_ERRORS] && strlen($RESPONSE->Exceptions) > 0) {
            $RESPONSE->XML .= "<gl_e h=\"" . base64_encode($hash) . "\">\r\n" . $RESPONSE->Exceptions . "</gl_e>\r\n";
        }
        if (($hash = substr(md5($RESPONSE->Internals), 0, 5)) != @$_POST[POST_INTERN_XMLCLIP_HASH_INTERN] && strlen($RESPONSE->Internals) > 0) {
            $RESPONSE->XML .= "<int_r h=\"" . base64_encode($hash) . "\">\r\n" . $RESPONSE->Internals . "</int_r>\r\n";
        }
        if (($hash = substr(md5($RESPONSE->Groups), 0, 5)) != @$_POST[POST_INTERN_XMLCLIP_HASH_GROUPS] && strlen($RESPONSE->Groups) > 0) {
            $RESPONSE->XML .= "<int_d h=\"" . base64_encode($hash) . "\">\r\n" . $RESPONSE->Groups . "</int_d>\r\n";
        }
        if (($hash = substr(md5($RESPONSE->InternalVcards), 0, 5)) != @$_POST[POST_INTERN_XMLCLIP_HASH_VISITCARDS]) {
            $RESPONSE->XML .= "<int_v h=\"" . base64_encode($hash) . "\">\r\n" . $RESPONSE->InternalVcards . "</int_v>\r\n";
        }
        if (($hash = substr(md5($RESPONSE->InternalProfilePictures), 0, 5)) != @$_POST[POST_INTERN_XMLCLIP_HASH_PICTURES_PROFILE]) {
            $RESPONSE->XML .= "<int_pp h=\"" . base64_encode($hash) . "\">\r\n" . $RESPONSE->InternalProfilePictures . "</int_pp>\r\n";
        }
        if (($hash = substr(md5($RESPONSE->InternalWebcamPictures), 0, 5)) != @$_POST[POST_INTERN_XMLCLIP_HASH_PICTURES_WEBCAM]) {
            $RESPONSE->XML .= "<int_wp h=\"" . base64_encode($hash) . "\">\r\n" . $RESPONSE->InternalWebcamPictures . "</int_wp>\r\n";
        }
        if (($hash = substr(md5($RESPONSE->Filter), 0, 5)) != @$_POST[POST_INTERN_XMLCLIP_HASH_FILTERED]) {
            $RESPONSE->XML .= "<ext_b h=\"" . base64_encode($hash) . "\">\r\n" . $RESPONSE->Filter . "</ext_b>\r\n";
        }
        if (($hash = substr(md5($RESPONSE->Tracking), 0, 5)) != @$_POST[POST_INTERN_XMLCLIP_HASH_EXTERN]) {
            $RESPONSE->XML .= "<ext_u h=\"" . base64_encode($hash) . "\">\r\n" . $RESPONSE->Tracking . "</ext_u>\r\n";
        }
        if ($RESPONSE->Archive != null) {
            $RESPONSE->XML .= "<ext_c>\r\n" . $RESPONSE->Archive . "</ext_c>\r\n";
        }
        if ($RESPONSE->Resources != null) {
            $RESPONSE->XML .= "<ext_res>\r\n" . $RESPONSE->Resources . "</ext_res>\r\n";
        }
        if ($RESPONSE->Ratings != null) {
            $RESPONSE->XML .= "<ext_r>\r\n" . $RESPONSE->Ratings . "</ext_r>\r\n";
        }
        if ($RESPONSE->Messages != null) {
            $RESPONSE->XML .= "<ext_m>\r\n" . $RESPONSE->Messages . "</ext_m>\r\n";
        }
        if (strlen($RESPONSE->Authentications) > 0) {
            $RESPONSE->XML .= "<gl_auths>\r\n" . $RESPONSE->Authentications . "\r\n</gl_auths>\r\n";
        }
        if (strlen($RESPONSE->Posts) > 0) {
            $RESPONSE->XML .= "<usr_p>\r\n" . $RESPONSE->Posts . "</usr_p>\r\n";
        }
        if (isset($_POST[POST_INTERN_ACCESSTEST])) {
            $RESPONSE->XML .= "<permission>" . base64_encode(getFolderPermissions()) . "</permission>";
        }
        if (SERVERSETUP || LOGIN || $INTERNAL[CALLER_SYSTEM_ID]->LastActive <= @filemtime(FILE_CONFIG)) {
            $RESPONSE->XML .= getConfig();
        }
        $RESPONSE->XML .= "</listen>";
        if (substr_count($RESPONSE->XML, "<") > 4 || $INTERNAL[CALLER_SYSTEM_ID]->Status == USER_STATUS_OFFLINE || isset($_POST[POST_GLOBAL_NO_LONG_POLL])) {
            break;
        } else {
            if (isset($_POST[POST_GLOBAL_SHOUT])) {
                break;
            }
            $wait = max($CONFIG["poll_frequency_clients"] - 1, 1);
            if (time() + $wait <= $start + getLongPollRuntime()) {
                sleep($wait);
            } else {
                break;
            }
        }
    }
}