<commit_before><?php

$SITE_DOMAIN = getenv('SITE_DOMAIN');

include '../util.php';

function get_events($form) {
    $connection = connect_db();

    $bounds = explode(',', $form['bounds']); 
    $southwest = array(
        'lng' => $bounds[0],
        'lat' => $bounds[1]
    );
    $northeast = array(
        'lng' => $bounds[2],
        'lat' => $bounds[3]
    );
    
    $query = sprintf("
        SELECT *
        FROM `events`
        WHERE
            `latitude` BETWEEN {$southwest['lat']} AND {$northeast['lat']}
            AND `longitude` BETWEEN {$southwest['lng']} AND {$northeast['lng']}
            AND `date` > DATE_SUB(CURDATE(), INTERVAL 30 DAY)
        LIMIT 1000
    ");
    $result = $connection->query($query);

    if (!$result) {
      die("Invalid query: " . $connection->error);
    }

    $events = array();
    while ($row = mysqli_fetch_assoc($result)){
      $events[] = $row;
    }

    mysqli_close($connection);

    header("Content-type: application/json");
    $response_data = array(
        'events' => $events
    );
    
    echo json_encode($response_data);
}

function subscribe($form) {
    $connection = connect_db();
    $guid = getGUID();
    $name = $form['name'] ? "\"{$form['name']}\"" : "NULL";
    $query = sprintf("
    INSERT INTO `subscriptions` (`guid`, `created`, `latitude`, `longitude`, `radius`, `name`, `email`)
    VALUES ('$guid', NOW(), {$form['center']['lat']}, {$form['center']['lng']}, {$form['radius']}, {$name}, '{$form['email']}')
    ");
    $result = $connection->query($query);
    
    if (!$result) {
      die("Invalid query: " . $connection->error);
    }

    mysqli_close($connection);
    <commit_msg>reformats queries slightly to enable syntax highlighting<commit_after><?php

$SITE_DOMAIN = getenv('SITE_DOMAIN');

include '../util.php';

function get_events($form) {
    $connection = connect_db();

    $bounds = explode(',', $form['bounds']); 
    $southwest = array(
        'lng' => $bounds[0],
        'lat' => $bounds[1]
    );
    $northeast = array(
        'lng' => $bounds[2],
        'lat' => $bounds[3]
    );
    
    $query = sprintf("SELECT *
        FROM `events`
        WHERE
            `latitude` BETWEEN {$southwest['lat']} AND {$northeast['lat']}
            AND `longitude` BETWEEN {$southwest['lng']} AND {$northeast['lng']}
            AND `date` > DATE_SUB(CURDATE(), INTERVAL 30 DAY)
        LIMIT 1000");
    $result = $connection->query($query);

    if (!$result) {
      die("Invalid query: " . $connection->error);
    }

    $events = array();
    while ($row = mysqli_fetch_assoc($result)){
      $events[] = $row;
    }

    mysqli_close($connection);

    header("Content-type: application/json");
    $response_data = array(
        'events' => $events
    );
    
    echo json_encode($response_data);
}

function subscribe($form) {
    $connection = connect_db();
    $guid = getGUID();
    $name = $form['name'] ? "\"{$form['name']}\"" : "NULL";
    $query = sprintf("INSERT INTO `subscriptions` 
    (`guid`, `created`, `latitude`, `longitude`, `radius`, `name`, `email`)
    VALUES ('$guid', NOW(), {$form['center']['lat']}, {$form['center']['lng']}, {$form['radius']}, {$name}, '{$form['email']}')
    ");
    $result = $connection->query($query);
    
    if (!$result) {
      die("Invalid query: " . $connection->error);
    }

    mysqli_close($connection);
    
{'fraction_non_alphanumeric': 0.21043324491600354, 'fraction_numerical': 0.0058944886531093425, 'mean_word_length': 2.8700114025085517, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, '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': '4783109', 'n_tokens_mistral': 1162, 'n_tokens_neox': 1118, 'n_words': 224}