function _errorlog_logErrorRecord($logType, $logData)
{
    // limit errors logged per session (to prevent infinite loops from logging infinite errors)
    $maxErrorsPerPage = 25;
    $maxErrorsReached = false;
    static $totalErrorsLogged = 0;
    $totalErrorsLogged++;
    if ($totalErrorsLogged > $maxErrorsPerPage + 1) {
        return;
    }
    // ignore any errors after max error limit
    if ($totalErrorsLogged > $maxErrorsPerPage) {
        $maxErrorsReached = true;
    }
    // get summary of CMS user data
    $CMS_USER = getCurrentUserFromCMS();
    $subsetFields = array();
    foreach (array('num', 'username') as $field) {
        if (isset($CMS_USER[$field])) {
            $subsetFields[$field] = $CMS_USER[$field];
        }
    }
    $subsetFields['_tableName'] = 'accounts';
    $cms_user_summary = print_r($subsetFields, true);
    // get summary of WEB user data
    $WEB_USER = getCurrentUser();
    $subsetFields = array();
    foreach (array('num', 'username') as $field) {
        if (isset($WEB_USER[$field])) {
            $subsetFields[$field] = $WEB_USER[$field];
        }
    }
    $subsetFields['_tableName'] = accountsTable();
    $web_user_summary = print_r($subsetFields, true);
    // create error message
    if ($maxErrorsReached) {
        $errorMessage = t(sprintf("Max error limit reached! Only the first %s errors per page will be logged.", $maxErrorsPerPage));
    } else {
        if (isset($logData['errno'])) {
            $errorName = _errorLog_erronoToConstantName($logData['errno']);
        } else {
            $errorName = 'UNKNOWN_ERROR';
        }
        $errorMessage = "{$errorName}: " . (isset($logData['errstr']) ? $logData['errstr'] : '');
    }
    // create $logDataSummary without
    $logDataSummary = $logData;
    if (array_key_exists('errcontext', $logData)) {
        $logDataSummary['errcontext'] = "*** in symbol table field above ***";
    }
    //  create log record data
    $colsToValues = array('dateLogged=' => 'NOW()', 'updatedDate=' => 'NOW()', 'updatedByuserNum' => '0', 'error' => $errorMessage, 'url' => thisPageUrl(), 'filepath' => isset($logData['errfile']) ? $logData['errfile'] : '', 'line_num' => isset($logData['errline']) ? $logData['errline'] : '', 'user_cms' => isset($CMS_USER['num']) ? $cms_user_summary : '', 'user_web' => isset($WEB_USER['num']) ? $web_user_summary : '', 'http_user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '', 'remote_addr' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '', 'request_vars' => print_r($_REQUEST, true), 'get_vars' => print_r($_GET, true), 'post_vars' => print_r($_POST, true), 'cookie_vars' => print_r($_COOKIE, true), 'session_vars' => isset($_SESSION) ? print_r($_SESSION, true) : '', 'server_vars' => print_r($_SERVER, true), 'symbol_table' => isset($logData['errcontext']) ? print_r($logData['errcontext'], true) : '', 'raw_log_data' => print_r($logDataSummary, true), 'email_sent' => 0);
    // insert record
    $newRecordNum = mysql_insert('_error_log', utf8_force($colsToValues, true));
    // remove old log records
    $maxRecords = 900;
    $buffer = 100;
    // only erase records when we're this many over (to avoid erasing records every time)
    if (mysql_count('_error_log') > $maxRecords + $buffer) {
        $oldestRecordToSave_query = "SELECT * FROM `{$GLOBALS['TABLE_PREFIX']}_error_log` ORDER BY `num` DESC LIMIT 1 OFFSET " . ($maxRecords - 1);
        $oldestRecordToSave = mysql_get_query($oldestRecordToSave_query);
        if (!empty($oldestRecordToSave['num'])) {
            mysql_delete('_error_log', null, "num < {$oldestRecordToSave['num']}");
        }
    }
    // send email update
    if ($GLOBALS['SETTINGS']['advanced']['phpEmailErrors']) {
        register_shutdown_function('_errorlog_sendEmailAlert');
    }
}
Exemplo n.º 2
0
function utf8_force($stringOrArray, $replace4ByteUTF8 = false, $convertFromEncoding = '')
{
    // error checking
    if (mb_internal_encoding() != 'UTF-8') {
        // we default to assuming an incoming encoding of utf-8, so we want to check that's the case
        // we generally don't want to support scripts that run with some other internal encoding
        die(__FUNCTION__ . ": mb_internal_encoding() must be UTF-8, not '" . htmlerncode(mb_internal_encoding()) . "'");
    }
    if ($convertFromEncoding && !@mb_convert_encoding(1, $convertFromEncoding)) {
        // mb_convert_encoding() returns false if encoding isn't recognized
        die(__FUNCTION__ . ": unknown character set specified '" . htmlencode($convertFromEncoding) . "'");
    }
    // support recursively converting arrays
    if (is_array($stringOrArray)) {
        foreach ($stringOrArray as $index => $string) {
            $stringOrArray[$index] = utf8_force($string, $replace4ByteUTF8, $convertFromEncoding);
        }
        return $stringOrArray;
    }
    // convert string to UTF-8
    $string = $stringOrArray;
    $encoding = $convertFromEncoding ? $convertFromEncoding : 'UTF-8';
    // Note: encoding from utf-8 to utf-8 "fixes" invalid utf-8 (replaces invalid sequences with a replacement char ?)
    $utf8String = mb_convert_encoding($string, 'UTF-8', $encoding);
    // mb_convert_encodin() replaces unknown/invalid sequences with ascii "?"
    // replace 4-byte utf-8 for mysql compatability, see: http://dev.mysql.com/doc/refman/5.5/en/charset-unicode-utf8mb4.html
    // for security replace chars don't remove, see: http://unicode.org/reports/tr36/#Deletion_of_Noncharacters
    if ($replace4ByteUTF8) {
        $replacementChar = "�";
        /* For security replace don't remove, official replacement char looks like this: <?> see: http://unicode.org/reports/tr36/#Deletion_of_Noncharacters */
        $utf8String = preg_replace('/[\\xF0-\\xF7].../s', $replacementChar, $utf8String);
        // replace 4-byte utf-8 sequences that start with binary: 11110xxx
    }
    //
    return $utf8String;
}