<commit_before><?php

// Tries to log in to GG2 Forums
// Returns session ID, or FALSE on failure
function gg2_login($username, $password) {
    // Prepares post data
    $fields = [
        'user' => $username,
        'passwrd' => $password,
        'cookieneverexp' => '1'
    ];
    $fields_str = '';
    foreach($fields as $key => $value) {
        $fields_str .= urlencode($key) . '=' . urlencode($value) . '&';
    }
    rtrim($fields_str, '&');
    
    $ch = curl_init();
    
    // The URL that the login form posts to
    curl_setopt($ch, CURLOPT_URL, 'http://ganggarrison.com/forums/?action=login2;wap2');
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_str);
    
    // Redirect checking
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    
    // Silence (don't want to output returned page html to end-user)
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    
    $result = curl_exec($ch);
    
    // Find out what the resulting URL is
    $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
    
    curl_close($ch);
    
    // Find PHPSESSID parameter in URL
    $needle = 'PHPSESSID=';
    if (($pos = strpos($url, $needle)) !== FALSE) {
        $pos2 = strpos($url, ';', $pos);
        // return PHPSESSID value
        return substr($url, $pos + strlen($needle), $pos2 - $pos - strlen($needle));
    } else {
        // If there's no PHPSESSID, it failed
        return FALSE;
    }
}

// Tries to grab someone's name from their profile
// Probably can't fail (?)
function gg2_get_profilename($PHPSESSID) {
    $ch = curl_init();

    // Profile page
    curl_setopt($ch, CURLOPT_URL, 'http://ganggarrison.com/forums/index.php?action=profile;PHPSESSID=' . $PHPSESSID);

    // Silence (don't want to output returned page html to end-user)
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

    $result = curl_exec($ch);

    curl_close($ch);

    // Find profile name
    $needle = "\t\t\tSummary - ";
    file_put_contents('debug.txt', $result);
    $pos = strpos($result, $needle);
    $pos2 = strpos($result, "\n", $pos);
    $sc = substr($result, $pos + strlen($needle), $pos2 - $pos - strlen($needle));

    return $sc;
}

// Tries to change GG2 Forum signature
// Success is assumed (!)
function gg2_change_signature($PHPSESSID, $sig) {
    // First we need to make a GET request for the profile edit page
    
    $ch = curl_init();
    
    // Profile edit page
    curl_setopt($ch, CURLOPT_URL, 'http://ganggarrison.com/forums/index.php?action=profile;sa=forumProfile;PHPSESSID=' . $PHPSESSID);<commit_msg>Removed debug html dump<commit_after><?php

// Tries to log in to GG2 Forums
// Returns session ID, or FALSE on failure
function gg2_login($username, $password) {
    // Prepares post data
    $fields = [
        'user' => $username,
        'passwrd' => $password,
        'cookieneverexp' => '1'
    ];
    $fields_str = '';
    foreach($fields as $key => $value) {
        $fields_str .= urlencode($key) . '=' . urlencode($value) . '&';
    }
    rtrim($fields_str, '&');
    
    $ch = curl_init();
    
    // The URL that the login form posts to
    curl_setopt($ch, CURLOPT_URL, 'http://ganggarrison.com/forums/?action=login2;wap2');
    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_str);
    
    // Redirect checking
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    
    // Silence (don't want to output returned page html to end-user)
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    
    $result = curl_exec($ch);
    
    // Find out what the resulting URL is
    $url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
    
    curl_close($ch);
    
    // Find PHPSESSID parameter in URL
    $needle = 'PHPSESSID=';
    if (($pos = strpos($url, $needle)) !== FALSE) {
        $pos2 = strpos($url, ';', $pos);
        // return PHPSESSID value
        return substr($url, $pos + strlen($needle), $pos2 - $pos - strlen($needle));
    } else {
        // If there's no PHPSESSID, it failed
        return FALSE;
    }
}

// Tries to grab someone's name from their profile
// Probably can't fail (?)
function gg2_get_profilename($PHPSESSID) {
    $ch = curl_init();

    // Profile page
    curl_setopt($ch, CURLOPT_URL, 'http://ganggarrison.com/forums/index.php?action=profile;PHPSESSID=' . $PHPSESSID);

    // Silence (don't want to output returned page html to end-user)
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

    $result = curl_exec($ch);

    curl_close($ch);

    // Find profile name
    $needle = "\t\t\tSummary - ";
    $pos = strpos($result, $needle);
    $pos2 = strpos($result, "\n", $pos);
    $sc = substr($result, $pos + strlen($needle), $pos2 - $pos - strlen($needle));

    return $sc;
}

// Tries to change GG2 Forum signature
// Success is assumed (!)
function gg2_change_signature($PHPSESSID, $sig) {
    // First we need to make a GET request for the profile edit page
    
    $ch = curl_init();
    
    // Profile edit page
    curl_setopt($ch, CURLOPT_URL, 'http://ganggarrison.com/forums/index.php?action=profile;sa=forumProfile;PHPSESSID=' . $PHPSESSID);
{'fraction_non_alphanumeric': 0.15076743734214104, 'fraction_numerical': 0.004662910433262095, 'mean_word_length': 2.891156462585034, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, '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': '3899444', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1765, 'n_words': 430}