<commit_before><?php
    require_once "model.Comment.php";
    require_once "lib/Defensio.php";

    class Comments extends Modules {
        public function __init() {
            $this->addAlias("metaWeblog_newPost_preQuery", "metaWeblog_editPost_preQuery");
            $this->addAlias("post_grab", "posts_get");
            $this->addAlias("comment_grab", "comments_get");
        }

        static function __install() {
            $sql = SQL::current();
            $sql->query("CREATE TABLE IF NOT EXISTS __comments (
                             id INTEGER PRIMARY KEY AUTO_INCREMENT,
                             body LONGTEXT,
                             author VARCHAR(250) DEFAULT '',
                             author_url VARCHAR(128) DEFAULT '',
                             author_email VARCHAR(128) DEFAULT '',
                             author_ip INT(10) DEFAULT '0',
                             author_agent VARCHAR(255) DEFAULT '',
                             status VARCHAR(32) default 'denied',
                             signature VARCHAR(32) DEFAULT '',
                             post_id INTEGER DEFAULT '0',
                             user_id INTEGER DEFAULT '0',
                             created_at DATETIME DEFAULT '0000-00-00 00:00:00',
                             updated_at DATETIME DEFAULT '0000-00-00 00:00:00'
                         ) DEFAULT CHARSET=utf8");

            $config = Config::current();
            $config->set("default_comment_status", "denied");
            $config->set("allowed_comment_html", array("strong", "em", "blockquote", "code", "pre", "a"));
            $config->set("comments_per_page", 25);
            $config->set("defensio_api_key", null);
            $config->set("auto_reload_comments", 30);
            $config->set("enable_reload_comments", false);

            Group::add_permission("add_comment", "Add Comments");
            Group::add_permission("add_comment_private", "Add Comments to Private Posts");
            Group::add_permission("edit_comment", "Edit Comments");
            Group::add_permission("edit_own_comment", "Edit Own Comments");
            Group::add_permission("delete_comment", "Delete Comments");
            Group::add_permission("delete_own_comment", "Delete Own Comments");
            Group::add_permission("code_in_comments", "Can Use HTML In Comments");
        }

        static function __uninstall($confirm) {
            if ($confirm)
                SQL::current()->query("DROP TABLE __comments");

            $config = Config::current();
            $config->remove("default_comment_status");
            $config->remove("allowed_comment_html");
            $config->remove("comments_per_page");
            $config->remove("defensio_api_key");
            $config->remove("auto_reload_comments");
            $config->remove("enable_reload_comments");

            Group::remove_permission("add_comment");
            Group::remove_permission("add_comment_private");
            Group::remove_permission("edit_comment");
            Group::remove_permission("edit_own_comment");
            Group::remove_permission("delete_comment");
            Group::remove_permission("delete_own_comment");
            Group::remove_permission("code_in_comments");
        }

        static function route_add_comment() {
            $post = new Post($_POST['post_id'], array("drafts" => true));
            if (!Comment::user_can($post->id))
                show_403(__("Access Denied"), __("You cannot comment on this post.", "comments"));

            if (empty($_POST['author'])) error(__("Error"), __("Author can't be blank.", "comments"));
            if (empty($_POST['email']))  error(__("Error"), __("E-Mail address can't be blank.", "comments"));
            if (empty($_POST['body']))   error(__("Error"), __("Message can't be blank.", "comments"));
            Comment::create($_POST['author'],
                            $_POST['email'],
                            $_POST['url'],
                            $_POST['body'],
                            $post);
        }

        static function admin_update_comment() {
            if (empty($_POST))
                redirect("/admin/?action=manage_comments");

            $comment = new Comment($_POST['id']);
            if (!$comment->editable())
                show_403(__("Access Denied"), __("You do not have sufficient privileges to edit this comment.", "comments"));

            $visitor = Visitor::current();
            $status = ($visitor->group->can("edit_comment")) ? $_POST['status'] : $comment->status ;
            $created_at = ($visitor->group->can("edit_comment")) ? datetime($_POST['created_at']) : $comment->created_at ;
            $comment->update($_POST['author'],
                             $_POST['author_email'],
                             $_POST['author_url'],
                             $_POST['body'],
                             $status,
                             $created_at);

            if (isset($_POST['ajax']))
                exit("{ comment_id: ".$_POST['id'].", comment_timestamp: \"".$created_at."\" }");

            if ($_POST['status'] == "spam")
                Flash::notice(__("Comment updated."), "/admin/?action=manage_spam");
            else
                Flash::notice(_f("Comment updated. <a href=\"%s\">View Comment &rarr;</a>",
                                 array($comment->post->url()."#comment_".$comment->id),
                                 "comments"),
                              "/admin/?action=manage_comments");
        }

        static function admin_delete_comment($admin) {
            $comment = new Comment($_GET['id']);

            if (!$comment->deletable())
                show_403(__("Access Denied"), __("You do not have sufficient privileges to delete this comment.", "comments"));

            $admin->display("delete_comment", array("comments" => $comment));
        }

        static function admin_destroy_comment() {
            if (empty($_POST['id']))
                error(__("No ID Specified"), __("An ID is required to delete a comment.", "comments"));

            if ($_POST['destroy'] == "bollocks")
                redirect("/admin/?action=manage_comments");

            if (!isset($_POST['hash']) or $_POST['hash'] != Config::current()->secure_hashkey)<commit_msg>Fixed comment deleting without AJAX. [#246 state:resolved]<commit_after><?php
    require_once "model.Comment.php";
    require_once "lib/Defensio.php";

    class Comments extends Modules {
        public function __init() {
            $this->addAlias("metaWeblog_newPost_preQuery", "metaWeblog_editPost_preQuery");
            $this->addAlias("post_grab", "posts_get");
            $this->addAlias("comment_grab", "comments_get");
        }

        static function __install() {
            $sql = SQL::current();
            $sql->query("CREATE TABLE IF NOT EXISTS __comments (
                             id INTEGER PRIMARY KEY AUTO_INCREMENT,
                             body LONGTEXT,
                             author VARCHAR(250) DEFAULT '',
                             author_url VARCHAR(128) DEFAULT '',
                             author_email VARCHAR(128) DEFAULT '',
                             author_ip INT(10) DEFAULT '0',
                             author_agent VARCHAR(255) DEFAULT '',
                             status VARCHAR(32) default 'denied',
                             signature VARCHAR(32) DEFAULT '',
                             post_id INTEGER DEFAULT '0',
                             user_id INTEGER DEFAULT '0',
                             created_at DATETIME DEFAULT '0000-00-00 00:00:00',
                             updated_at DATETIME DEFAULT '0000-00-00 00:00:00'
                         ) DEFAULT CHARSET=utf8");

            $config = Config::current();
            $config->set("default_comment_status", "denied");
            $config->set("allowed_comment_html", array("strong", "em", "blockquote", "code", "pre", "a"));
            $config->set("comments_per_page", 25);
            $config->set("defensio_api_key", null);
            $config->set("auto_reload_comments", 30);
            $config->set("enable_reload_comments", false);

            Group::add_permission("add_comment", "Add Comments");
            Group::add_permission("add_comment_private", "Add Comments to Private Posts");
            Group::add_permission("edit_comment", "Edit Comments");
            Group::add_permission("edit_own_comment", "Edit Own Comments");
            Group::add_permission("delete_comment", "Delete Comments");
            Group::add_permission("delete_own_comment", "Delete Own Comments");
            Group::add_permission("code_in_comments", "Can Use HTML In Comments");
        }

        static function __uninstall($confirm) {
            if ($confirm)
                SQL::current()->query("DROP TABLE __comments");

            $config = Config::current();
            $config->remove("default_comment_status");
            $config->remove("allowed_comment_html");
            $config->remove("comments_per_page");
            $config->remove("defensio_api_key");
            $config->remove("auto_reload_comments");
            $config->remove("enable_reload_comments");

            Group::remove_permission("add_comment");
            Group::remove_permission("add_comment_private");
            Group::remove_permission("edit_comment");
            Group::remove_permission("edit_own_comment");
            Group::remove_permission("delete_comment");
            Group::remove_permission("delete_own_comment");
            Group::remove_permission("code_in_comments");
        }

        static function route_add_comment() {
            $post = new Post($_POST['post_id'], array("drafts" => true));
            if (!Comment::user_can($post->id))
                show_403(__("Access Denied"), __("You cannot comment on this post.", "comments"));

            if (empty($_POST['author'])) error(__("Error"), __("Author can't be blank.", "comments"));
            if (empty($_POST['email']))  error(__("Error"), __("E-Mail address can't be blank.", "comments"));
            if (empty($_POST['body']))   error(__("Error"), __("Message can't be blank.", "comments"));
            Comment::create($_POST['author'],
                            $_POST['email'],
                            $_POST['url'],
                            $_POST['body'],
                            $post);
        }

        static function admin_update_comment() {
            if (empty($_POST))
                redirect("/admin/?action=manage_comments");

            $comment = new Comment($_POST['id']);
            if (!$comment->editable())
                show_403(__("Access Denied"), __("You do not have sufficient privileges to edit this comment.", "comments"));

            $visitor = Visitor::current();
            $status = ($visitor->group->can("edit_comment")) ? $_POST['status'] : $comment->status ;
            $created_at = ($visitor->group->can("edit_comment")) ? datetime($_POST['created_at']) : $comment->created_at ;
            $comment->update($_POST['author'],
                             $_POST['author_email'],
                             $_POST['author_url'],
                             $_POST['body'],
                             $status,
                             $created_at);

            if (isset($_POST['ajax']))
                exit("{ comment_id: ".$_POST['id'].", comment_timestamp: \"".$created_at."\" }");

            if ($_POST['status'] == "spam")
                Flash::notice(__("Comment updated."), "/admin/?action=manage_spam");
            else
                Flash::notice(_f("Comment updated. <a href=\"%s\">View Comment &rarr;</a>",
                                 array($comment->post->url()."#comment_".$comment->id),
                                 "comments"),
                              "/admin/?action=manage_comments");
        }

        static function admin_delete_comment($admin) {
            $comment = new Comment($_GET['id']);

            if (!$comment->deletable())
                show_403(__("Access Denied"), __("You do not have sufficient privileges to delete this comment.", "comments"));

            $admin->display("delete_comment", array("comment" => $comment));
        }

        static function admin_destroy_comment() {
            if (empty($_POST['id']))
                error(__("No ID Specified"), __("An ID is required to delete a comment.", "comments"));

            if ($_POST['destroy'] == "bollocks")
                redirect("/admin/?action=manage_comments");

            if (!isset($_POST['hash']) or $_POST['hash'] != Config::current()->secure_hashkey)
{'fraction_non_alphanumeric': 0.14852803006576887, 'fraction_numerical': 0.010100219229564673, 'mean_word_length': 1.9677044609665428, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '791027', 'n_tokens_mistral': 3287, 'n_tokens_neox': 3086, 'n_words': 631}