<commit_before><?php

class docs extends Controller {

    function __construct() {
        $this->load_library("http_lib", "http");
        $this->load_library("cas_lib", "cas");
        $this->cas->forceAuthentication();

        $this->load_model("docs_model");
        $this->load_model("auth_model");

        $this->user = $this->cas->getUser();
        $this->is_admin = $this->auth_model->is_admin($this->user);
    }

    private function edit() {
        if (!empty($_POST["save"]) && !empty($_POST["file_id"])
            && !empty($_POST["name"]) && !empty($_POST["slang"]))
        {
            $file_id = $_POST["file_id"];
            $name = $_POST["name"];
            $slang = $_POST["slang"];
            $data = $_POST["data"] ?: "";
            $save = $this->docs_model->update_file($file_id, $name, $slang, $data);
            if ($save === false) {
                return "Could not save file";
            }

            $path = $this->docs_model->get_file_path($file_id);
            $this->http->redirect(base_url() . "docs" . $path . "edit/");
        }

        if (!empty($_POST["add"]) && !empty($_POST["parent_id"])
            && !empty($_POST["name"]) && !empty($_POST["slang"]))
        {
            $parent_id = $_POST["parent_id"];
            $name = $_POST["name"];
            $slang = $_POST["slang"];
            $type = $_POST["type"];

            $add = $this->docs_model->new_file($parent_id, $name, $slang, $type, $this->user);
            if ($add === false) {
                return "Could not add file";
            }

            $path = $this->docs_model->get_file_path($parent_id) . $slang . "/";
            $this->http->redirect(base_url() . "docs" . $path . "edit/");
        }
    }

    function read() {
        $path = func_get_args();

        $edit = false;
        if ($this->is_admin && count($path)
            && $path[count($path) - 1] == "edit")
        {
            $edit = true;
        }

        $file_id = $this->docs_model->get_path_id($path);
        $file_type = $this->docs_model->get_file_type($file_id);
        $file = $this->docs_model->get_file($file_id);

        if ($this->is_admin && $edit) {
            $error = $this->edit();

            if ($file_type == "directory") {
                $file["error"] = $error;
                $this->load_view("directory_edit", $file);
            } else if ($file_type == "file") {
                $file["error"] = $error;
                $this->load_view("file_edit", $file);
            } else {
                $this->http->err_404();
            }
        } else {
            if ($file_type == "directory") {
                $file["data"] = $this->docs_model->get_directory($file_id);
                $file["is_admin"] = $this->is_admin;
                $this->load_view("directory", $file);
            } else if ($file_type == "file") {<commit_msg>Fix minor issues<commit_after><?php

class docs extends Controller {

    function __construct() {
        $this->load_library("http_lib", "http");
        $this->load_library("cas_lib", "cas");
        $this->cas->forceAuthentication();

        $this->load_model("docs_model");
        $this->load_model("auth_model");

        $this->user = $this->cas->getUser();
        $this->is_admin = $this->auth_model->is_admin($this->user);
    }

    private function edit() {
        if (!empty($_POST["save"]) && !empty($_POST["file_id"])
            && !empty($_POST["name"]) && !empty($_POST["slang"]))
        {
            $file_id = $_POST["file_id"];
            $name = $_POST["name"];
            $slang = $_POST["slang"];
            $data = $_POST["data"] ?: "";
            $save = $this->docs_model->update_file($file_id, $name, $slang, $data);
            if ($save === false) {
                return "Could not save file";
            }

            $path = $this->docs_model->get_file_path($file_id);
            $this->http->redirect(base_url() . "docs" . $path . "edit/");
        }

        if (!empty($_POST["add"]) && isset($_POST["parent_id"])
            && !empty($_POST["name"]) && !empty($_POST["slang"]))
        {
            $parent_id = $_POST["parent_id"];
            $name = $_POST["name"];
            $slang = $_POST["slang"];
            $type = $_POST["type"];

            $add = $this->docs_model->new_file($parent_id, $name, $slang, $type, $this->user);
            if ($add === false) {
                return "Could not add file";
            }

            $path = $this->docs_model->get_file_path($parent_id) . $slang . "/";
            $this->http->redirect(base_url() . "docs" . $path . "edit/");
        }
    }

    function read() {
        $path = func_get_args();

        $edit = false;
        if ($this->is_admin && count($path)
            && $path[count($path) - 1] == "edit")
        {
            array_pop($path);
            $edit = true;
        }

        $file_id = $this->docs_model->get_path_id($path);
        $file_type = $this->docs_model->get_file_type($file_id);
        $file = $this->docs_model->get_file($file_id);

        if ($this->is_admin && $edit) {
            $error = $this->edit();

            if ($file_type == "directory") {
                $file["error"] = $error;
                $this->load_view("directory_edit", $file);
            } else if ($file_type == "file") {
                $file["error"] = $error;
                $this->load_view("file_edit", $file);
            } else {
                $this->http->err_404();
            }
        } else {
            if ($file_type == "directory") {
                $file["data"] = $this->docs_model->get_directory($file_id);
                $file["is_admin"] = $this->is_admin;
                $this->load_view("directory", $file);
            } else if ($file_type == "file") {
{'fraction_non_alphanumeric': 0.19775862068965516, 'fraction_numerical': 0.001379310344827586, 'mean_word_length': 1.8661067193675889, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 89, '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': '5361207', 'n_tokens_mistral': 1824, 'n_tokens_neox': 1772, 'n_words': 289}