<commit_before><!DOCTYPE html>
<html>
<head>
    <title>Shortener</title>
    <meta charset="utf-8"/>
    <link rel="stylesheet" href="commun.css"/>
</head>

<body><?php
include("bdd.php");

if (isset($_GET['site']) && $_GET['site'] != "") //url shortened
{
    /*  BDD plan
        TABLE : shortener
        id | short | url | comment | views | id_user | date
    */

    $site = $_GET['site'];

    $req_site_exists = "SELECT count(*) FROM shortener WHERE short='" . $site . "';"; //does the site exist

    $res_site_exists = $connexion->query($req_site_exists);
    $res_site_exists->setFetchMode(PDO::FETCH_OBJ);
    $res_site_exists = $res_site_exists->fetchColumn();

    if ($res_site_exists > 0) //if it exists
    {
        $get_site = $connexion->prepare('SELECT url, id, views FROM shortener WHERE short=?');
        $get_site->execute(array($site));
        $res_site = $get_site->fetch(PDO::FETCH_ASSOC);

        $views_plus_1 = $res_site['views'] + 1;

        $query_update = $connexion->prepare('UPDATE shortener SET views=? WHERE id=?');
        $query_update->execute(array($views_plus_1, $res_site['id']));

        header('Location: ' . $res_site['url']);
    } else {
        header('Location: /');
    }
} else if (isset($_GET['shorten']) && $_GET['shorten'] != "") {
    $shorten = $_GET['shorten'];
    if (preg_match("_(^|[\s.:;?\-\]<\(])(https?://[-\w;/?:@&=+$\|\_.!~*\|'()\[\]%#,?]+[\w/#](\(\))?)(?=$|[\s',\|\(\).:;?\-\[\]>\)])_i", $shorten)) {
        $unic = 0;
        while ($unic == 0) {
            $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
            $url_shortened = '';
            for ($i = 0; $i < 4; $i++) {
                $url_shortened .= $characters[rand(0, strlen($characters) - 1)];
            }

            $req_verify_url = "SELECT count(*) FROM shortener WHERE short='" . $url_shortened . "';"; //select the post

            $verify_url = $connexion->query($req_verify_url);
            $verify_url->setFetchMode(PDO::FETCH_OBJ);
            $verify_url = $verify_url->fetchColumn();

            if ($verify_url == 0) {
                $unic = 1;
            }<commit_msg>Update index.php<commit_after><!DOCTYPE html>
<html>
<head>
    <title>Shortener</title>
    <meta charset="utf-8"/>
    <link rel="stylesheet" href="commun.css"/>
</head>

<body><?php
include("bdd.php");

if (isset($_GET['site']) && $_GET['site'] != "") //url shortened
{
    /*  BDD plan
        TABLE : shortener
        id | short | url | comment | views | id_user | date
    */

    $site = $_GET['site'];

    $req_site_exists = "SELECT count(*) FROM shortener WHERE short='" . $site . "';"; //does the site exist

    $res_site_exists = $connexion->query($req_site_exists);
    $res_site_exists->setFetchMode(PDO::FETCH_OBJ);
    $res_site_exists = $res_site_exists->fetchColumn();

    if ($res_site_exists > 0) //if it exists
    {
        $get_site = $connexion->prepare('SELECT url, id, views FROM shortener WHERE short=?');
        $get_site->execute(array($site));
        $res_site = $get_site->fetch(PDO::FETCH_ASSOC);

        $views_plus_1 = $res_site['views'] + 1;

        $query_update = $connexion->prepare('UPDATE shortener SET views=? WHERE id=?');
        $query_update->execute(array($views_plus_1, $res_site['id']));

        header('Location: ' . $res_site['url']);
    } else {
        header('Location: /');
    }
} else if (isset($_GET['shorten']) && $_GET['shorten'] != "") {
    $shorten = $_GET['shorten'];
    if (preg_match("_(^|[\s.:;?\-\]<\(])(https?://[-\w;/?:@&=+$\|\_.!~*\|'()\[\]%#,?]+[\w/#](\(\))?)(?=$|[\s',\|\(\).:;?\-\[\]>\)])_i", $shorten)) {
        $unic = 0;
        while ($unic == 0) {
            $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
            $url_shortened = '';
            for ($i = 0; $i < 5; $i++) { //This number is the number of letters after the adress
                $url_shortened .= $characters[rand(0, strlen($characters) - 1)];
            }

            $req_verify_url = "SELECT count(*) FROM shortener WHERE short='" . $url_shortened . "';"; //select the post

            $verify_url = $connexion->query($req_verify_url);
            $verify_url->setFetchMode(PDO::FETCH_OBJ);
            $verify_url = $verify_url->fetchColumn();

            if ($verify_url == 0) {
                $unic = 1;
            }
{'fraction_non_alphanumeric': 0.21485532011847802, 'fraction_numerical': 0.010480747322852585, 'mean_word_length': 2.7171888230313295, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 47, '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': '279162', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1520, 'n_words': 271}