<commit_before><?php

/**
 * library with user functions
 *  *.
 */
require_once dirname(__FILE__) . '/accesscheck.php';

function initialiseUserSession()
{
    if (!is_array($_SESSION['userdata'])) {
        $_SESSION['userdata'] = array();
    }
}

function getEveryoneGroupID()
{
    $ev_req = Sql_Fetch_Row_Query('select id from groups where name = "Everyone"');
    $everyone_groupid = $ev_req[0];
    if (!$everyone_groupid) {
        Sql_Query('insert into groups (name) values("Everyone")');
        $everyone_groupid = Sql_Insert_Id();
    }

    return $everyone_groupid;
}

function getUniqid($table = '')
{
    global $tables;
    if (!$table) {
        if ($tables['user']) {
            $table = $tables['user'];
        } else {
            $table = 'user';
        }
    }
    $id = md5(mt_rand() . uniqid(time(), true)); ##17603 better random CID value on Windows

    /* this doesn't scale very well, do this offline
    # make sure it is really unique
    $req = Sql_Query("select id from $table where uniqid = \"$id\"");
    while (Sql_Affected_rows()) {
      $id = md5(uniqid(mt_rand()));
      $req = Sql_Query("select id from $table where uniqid = \"$id\"");
    }
    */
    return $id;
}

function userSelect($fieldname, $current = '')
{
    global $tables;
    $html = sprintf('<select name="%s">', $fieldname);
    $req = Sql_Query(sprintf('select id,email from %s order by email', $tables['user']));
    while ($row = Sql_Fetch_Array($req)) {
        $html .= sprintf('<option value="%d" %s>%s</option>', $row['id'],
            $current == $row['id'] ? 'selected="selected"' : '', $row['email']);
    }
    $html .= '</select>';

    return $html;
}

function deleteUser($id)
{
    global $tables;
    Sql_Query(sprintf('delete from %s where userid = %d', $tables['listuser'], $id));
    Sql_Query(sprintf('delete from %s where userid = %d', $tables['user_attribute'], $id));
    Sql_Query(sprintf('delete from %s where userid = %d', $tables['usermessage'], $id));<commit_msg>add function to obfuscate an email address<commit_after><?php

/**
 * library with user functions
 *  *.
 */
require_once dirname(__FILE__) . '/accesscheck.php';

function initialiseUserSession()
{
    if (!is_array($_SESSION['userdata'])) {
        $_SESSION['userdata'] = array();
    }
}

function getEveryoneGroupID()
{
    $ev_req = Sql_Fetch_Row_Query('select id from groups where name = "Everyone"');
    $everyone_groupid = $ev_req[0];
    if (!$everyone_groupid) {
        Sql_Query('insert into groups (name) values("Everyone")');
        $everyone_groupid = Sql_Insert_Id();
    }

    return $everyone_groupid;
}

function getUniqid($table = '')
{
    global $tables;
    if (!$table) {
        if ($tables['user']) {
            $table = $tables['user'];
        } else {
            $table = 'user';
        }
    }
    $id = md5(mt_rand() . uniqid(time(), true)); ##17603 better random CID value on Windows

    /* this doesn't scale very well, do this offline
    # make sure it is really unique
    $req = Sql_Query("select id from $table where uniqid = \"$id\"");
    while (Sql_Affected_rows()) {
      $id = md5(uniqid(mt_rand()));
      $req = Sql_Query("select id from $table where uniqid = \"$id\"");
    }
    */
    return $id;
}

function obfuscateString($string) {
    $l = strlen(($string));
    if ($l > 3) {
        $obf = substr($string, 0, 1);
        $obf .= str_repeat('*', $l - 2);
        $obf .= substr($string, -1, 1);
    } else {
        $obf = str_repeat('*', $l);
    }
    return $obf;
}

function obfuscateEmailAddress($emailAddress) {
    if (is_email($emailAddress)) {

        list($userName, $domain) = explode('@', strtolower($emailAddress));

        $obf = obfuscateString($userName) . '@';

        $domainParts = explode('.', $domain);
        $TLD = array_pop($domainParts);

        foreach ($domainParts as $dPart) {
            $obf .= obfuscateString($dPart) . '.';
        }

        return $obf . $TLD;
    }
    return $emailAddress;
}

function userSelect($fieldname, $current = '')
{
    global $tables;
    $html = sprintf('<select name="%s">', $fieldname);
    $req = Sql_Query(sprintf('select id,email from %s order by email', $tables['user']));
    while ($row = Sql_Fetch_Array($req)) {
        $html .= sprintf('<option value="%d" %s>%s</option>', $row['id'],
            $current == $row['id'] ? 'selected="selected"' : '', $row['email']);
    }
    $html .= '</select>';

    return $html;
}

function deleteUser($id)
{
    global $tables;
    Sql_Query(sprintf('delete from %s where userid = %d', $tables['listuser'], $id));
    Sql_Query(sprintf('delete from %s where userid = %d', $tables['user_attribute'], $id));
    Sql_Query(sprintf('delete from %s where userid = %d', $tables['usermessage'], $id));
{'fraction_non_alphanumeric': 0.18440309429228519, 'fraction_numerical': 0.004599623667154506, 'mean_word_length': 3.068027210884354, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7306482', 'n_tokens_mistral': 1600, 'n_tokens_neox': 1584, 'n_words': 374}