<commit_before><?php

define('SRC_PATH', dirname(__FILE__) . '/../');

$controller = new controller();
$data = (isset($_GET['method'])) ? $_GET['method'] : 'index';

if (method_exists($controller,$data)){
    call_user_func([$controller, $data], '');
}else{
    header("HTTP/1.1 404 Not Found");
    echo 'Not Found';
}


class controller
{

    public function __construct()
    {
        if (!isset($_SESSION)){
            session_start();
        }

        require_once(SRC_PATH . 'models/image_crop.php');
    }

    /**
     * upload image list
     */
    public function index()
    {
        $data['message'] = isset($_SESSION['message']) ? $_SESSION['message'] : '';
        unset($_SESSION['message']);

        // get file list
        $file_links = [];
        foreach (glob("./uploaded/*") as $filename) {
            $file_links[] = $filename;
        }
        $data['file_links'] = $file_links;

        $this->view('index.php', $data);
    }

    /**
     * image confirm (jpeg orientaiton fixed)
     */
    public function confirm()
    {
        // check select file
        if (empty($_FILES['userfile']['tmp_name']) || !is_uploaded_file($_FILES['userfile']['tmp_name'])) {
            $_SESSION['message'] = 'file is not select';
            $this->index();
            return;
        }
        $filepath = $_FILES['userfile']['tmp_name'];

        // check mime type
        $info = getimagesize($filepath);
        if (!$info) {
            $_SESSION['message'] = 'file format is invalid';
            $this->index();
            return;
        }

        // iamge adjust
        $image_crop = new image_crop();
        $image_crop->crop($filepath, $info['mime']);

        // encode base64
        $image = file_get_contents($filepath);
        $base64 = base64_encode($image);
        $data['base64'] = $base64;
        $data['mime_type'] = $info['mime'];

        $validation_token = hash("sha256", $base64) . strlen($base64);
        $_SESSION['validation_token'] = $validation_token;

        $this->view('confirm.php', $data);
    }

    /**
     * file upload
     */<commit_msg>Optimize controller<commit_after><?php

define('SRC_PATH', dirname(__FILE__) . '/../');

$controller = new controller();
$data = (isset($_GET['method'])) ? $_GET['method'] : 'index';

if (method_exists($controller,$data)){
    call_user_func([$controller, $data], '');
}else{
    header("HTTP/1.1 404 Not Found");
    echo 'Not Found';
}


class controller
{

    public function __construct()
    {
        if (!isset($_SESSION)){
            session_start();
        }

        require_once(SRC_PATH . 'models/image_crop.php');
    }

    /**
     * upload image list
     */
    public function index()
    {
        $data['message'] = isset($_SESSION['message']) ? $_SESSION['message'] : '';
        unset($_SESSION['message']);

        // get file list
        $file_links = [];
        foreach (glob("./uploaded/*") as $filename) {
            $file_links[] = $filename;
        }
        $data['file_links'] = $file_links;

        $this->view('index.php', $data);
    }

    /**
     * image confirm (jpeg orientaiton fixed)
     */
    public function confirm()
    {
        // check select file
        if (empty($_FILES['userfile']['tmp_name']) || !is_uploaded_file($_FILES['userfile']['tmp_name'])) {
            $_SESSION['message'] = 'file is not select';
            $this->index();
            return;
        }
        $filepath = $_FILES['userfile']['tmp_name'];

        // check mime type & adjust
        $info = getimagesize($filepath);
        $image_crop = new image_crop();
        if (!$info && $image_crop->crop($filepath, $info['mime'])) {
            $_SESSION['message'] = 'file format is invalid';
            $this->index();
            return;
        }

        // encode base64
        $image = file_get_contents($filepath);
        $base64 = base64_encode($image);
        $data['base64'] = $base64;
        $data['mime_type'] = $info['mime'];

        $validation_token = hash("sha256", $base64) . strlen($base64);
        $_SESSION['validation_token'] = $validation_token;

        $this->view('confirm.php', $data);
    }

    /**
     * file upload
     */
{'fraction_non_alphanumeric': 0.18091168091168092, 'fraction_numerical': 0.010446343779677113, 'mean_word_length': 2.248265227447957, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, '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': '1520880', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1249, 'n_words': 240}