<commit_before><?php
    /**
     * Class: Post
     * The Post model.
     *
     * See Also:
     *     <Model>
     */
    class Post extends Model {
        public $belongs_to = "user";

        # Array: $url_attrs
        # The translation array of the post URL setting to regular expressions.
        # Passed through the route_code filter.
        static $url_attrs = array('(year)'     => '([0-9]{4})',
                                  '(month)'    => '([0-9]{1,2})',
                                  '(day)'      => '([0-9]{1,2})',
                                  '(hour)'     => '([0-9]{1,2})',
                                  '(minute)'   => '([0-9]{1,2})',
                                  '(second)'   => '([0-9]{1,2})',
                                  '(id)'       => '([0-9]+)',
                                  '(author)'   => '([^\/]+)',
                                  '(clean)'    => '([^\/]+)',
                                  '(url)'      => '([^\/]+)',
                                  '(feather)'  => '([^\/]+)',
                                  '(feathers)' => '([^\/]+)');

        /**
         * Function: __construct
         * See Also:
         *     <Model::grab>
         */
        public function __construct($post_id = null, $options = array()) {
            if (!isset($post_id) and empty($options)) return;

            if (isset($options["where"]) and !is_array($options["where"]))
                $options["where"] = array($options["where"]);
            elseif (!isset($options["where"]))
                $options["where"] = array();

            $has_status = false;
            foreach ($options["where"] as $key => $val)
                if (is_int($key) and substr_count($val, "status") or $key == "status")
                    $has_status = true;

            if (!XML_RPC) {
                $visitor = Visitor::current();
                $private = (isset($options["drafts"]) and $options["drafts"] and $visitor->group->can("view_draft")) ?
                               self::statuses(array("draft")) :
                               self::statuses();

                $options["where"][] = self::feathers();

                if (!$has_status)
                    $options["where"][] = $private;
            }

            $options["left_join"][] = array("table" => "post_attributes",
                                            "where" => "post_id = posts.id");
            $options["select"] = array_merge(array("posts.*",
                                                   "post_attributes.name AS attribute_names",
                                                   "post_attributes.value AS attribute_values"),
                                             fallback($options["select"], array(), true));
            $options["ignore_dupes"] = array("attribute_names", "attribute_values");

            parent::grab($this, $post_id, $options);

            if ($this->no_results)
                return false;

            $this->attribute_values = (array) $this->attribute_values;
            $this->attribute_names  = (array) $this->attribute_names;

            $this->attributes = ($this->attribute_names) ?
                                    array_combine($this->attribute_names, $this->attribute_values) :
                                    array() ;

            $this->filtered = (!isset($options["filter"]) or $options["filter"]) and !XML_RPC;
            $this->slug = $this->url;

            fallback($this->clean, $this->url);

            $this->parse();
        }

        /**
         * Function: find
         * See Also:
         *     <Model::search>
         */
        static function find($options = array(), $options_for_object = array(), $debug = false) {
            if (isset($options["where"]) and !is_array($options["where"]))
                $options["where"] = array($options["where"]);
            elseif (!isset($options["where"]))
                $options["where"] = array();

            $has_status = false;
            foreach ($options["where"] as $key => $val)
                if ((is_int($key) and substr_count($val, "status")) or $key === "status")
                    $has_status = true;

            if (!XML_RPC) {
                $visitor = Visitor::current();
                $private = (isset($options["drafts"]) and $options["drafts"] and $visitor->group->can("view_draft")) ?
                               self::statuses(array("draft")) :
                               self::statuses() ;

                $options["where"][] = self::feathers();

                if (!$has_status)
                    $options["where"][] = $private;
            }

            $options["left_join"][] = array("table" => "post_attributes",
                                            "where" => "post_id = posts.id");
            $options["select"] = array_merge(array("posts.*",
                                                   "post_attributes.name AS attribute_names",
                                                   "post_attributes.value AS attribute_values"),
                                             fallback($options["select"], array(), true));
            $options["ignore_dupes"] = array("attribute_names", "attribute_values");

            fallback($options["order"], "pinned DESC, created_at DESC, id DESC");

            return parent::search(get_class(), $options, $options_for_object);
        }

        /**
         * Function: add
         * Adds a post to the database with the passed XML, sanitized URL, and unique URL. The rest is read from $_POST.
         *
         * Trackbacks are automatically sent based on the contents of $_POST['trackbacks'].
         * Most of the $_POST variables will fall back gracefully if they don't exist, e.g. if they're posting from the Bookmarklet.
         *
         * Calls the add_post trigger with the inserted post and extra options.
         *
         * Parameters:
         *     $values - The data to insert.
         *     $clean - The sanitized URL (or empty to default to "(feather).(new post's id)").
         *     $url - The unique URL (or empty to default to "(feather).(new post's id)").
         *     $feather - The feather to post as.<commit_msg>Fixed *_own_* Group permissions. [#237 state:resolved]<commit_after><?php
    /**
     * Class: Post
     * The Post model.
     *
     * See Also:
     *     <Model>
     */
    class Post extends Model {
        public $belongs_to = "user";

        # Array: $url_attrs
        # The translation array of the post URL setting to regular expressions.
        # Passed through the route_code filter.
        static $url_attrs = array('(year)'     => '([0-9]{4})',
                                  '(month)'    => '([0-9]{1,2})',
                                  '(day)'      => '([0-9]{1,2})',
                                  '(hour)'     => '([0-9]{1,2})',
                                  '(minute)'   => '([0-9]{1,2})',
                                  '(second)'   => '([0-9]{1,2})',
                                  '(id)'       => '([0-9]+)',
                                  '(author)'   => '([^\/]+)',
                                  '(clean)'    => '([^\/]+)',
                                  '(url)'      => '([^\/]+)',
                                  '(feather)'  => '([^\/]+)',
                                  '(feathers)' => '([^\/]+)');

        /**
         * Function: __construct
         * See Also:
         *     <Model::grab>
         */
        public function __construct($post_id = null, $options = array()) {
            if (!isset($post_id) and empty($options)) return;

            if (isset($options["where"]) and !is_array($options["where"]))
                $options["where"] = array($options["where"]);
            elseif (!isset($options["where"]))
                $options["where"] = array();

            $has_status = false;
            foreach ($options["where"] as $key => $val)
                if (is_int($key) and substr_count($val, "status") or $key == "status")
                    $has_status = true;

            if (!XML_RPC) {
                $options["where"][] = self::feathers();

                if (!$has_status) {
                    $visitor = Visitor::current();
                    $private = (isset($options["drafts"]) and $options["drafts"] and $visitor->group->can("view_draft")) ?
                                   self::statuses(array("draft")) :
                                   self::statuses() ;

                    if (isset($options["drafts"]) and $options["drafts"] and $visitor->group->can("view_own_draft")) {
                        $private.= " OR (status = 'draft' AND user_id = :visitor_id)";
                        $options["params"][":visitor_id"] = $visitor->id;
                    }

                    $options["where"][] = $private;
                }
            }

            $options["left_join"][] = array("table" => "post_attributes",
                                            "where" => "post_id = posts.id");
            $options["select"] = array_merge(array("posts.*",
                                                   "post_attributes.name AS attribute_names",
                                                   "post_attributes.value AS attribute_values"),
                                             fallback($options["select"], array(), true));
            $options["ignore_dupes"] = array("attribute_names", "attribute_values");

            parent::grab($this, $post_id, $options);

            if ($this->no_results)
                return false;

            $this->attribute_values = (array) $this->attribute_values;
            $this->attribute_names  = (array) $this->attribute_names;

            $this->attributes = ($this->attribute_names) ?
                                    array_combine($this->attribute_names, $this->attribute_values) :
                                    array() ;

            $this->filtered = (!isset($options["filter"]) or $options["filter"]) and !XML_RPC;
            $this->slug = $this->url;

            fallback($this->clean, $this->url);

            $this->parse();
        }

        /**
         * Function: find
         * See Also:
         *     <Model::search>
         */
        static function find($options = array(), $options_for_object = array(), $debug = false) {
            if (isset($options["where"]) and !is_array($options["where"]))
                $options["where"] = array($options["where"]);
            elseif (!isset($options["where"]))
                $options["where"] = array();

            $has_status = false;
            foreach ($options["where"] as $key => $val)
                if ((is_int($key) and substr_count($val, "status")) or $key === "status")
                    $has_status = true;

            if (!XML_RPC) {
                $options["where"][] = self::feathers();

                if (!$has_status) {
                    $visitor = Visitor::current();
                    $private = (isset($options["drafts"]) and $options["drafts"] and $visitor->group->can("view_draft")) ?
                                   self::statuses(array("draft")) :
                                   self::statuses() ;

                    if (isset($options["drafts"]) and $options["drafts"] and $visitor->group->can("view_own_draft")) {
                        $private.= " OR (status = 'draft' AND user_id = :visitor_id)";
                        $options["params"][":visitor_id"] = $visitor->id;
                    }

                    $options["where"][] = $private;
                }
            }

            $options["left_join"][] = array("table" => "post_attributes",
                                            "where" => "post_id = posts.id");
            $options["select"] = array_merge(array("posts.*",
                                                   "post_attributes.name AS attribute_names",
                                                   "post_attributes.value AS attribute_values"),
                                             fallback($options["select"], array(), true));
            $options["ignore_dupes"] = array("attribute_names", "attribute_values");

            fallback($options["order"], "pinned DESC, created_at DESC, id DESC");

            return parent::search(get_class(), $options, $options_for_object);
        }

        /**
         * Function: add
         * Adds a post to the database with the passed XML, sanitized URL, and unique URL. The rest is read from $_POST.
         *
         * Trackbacks are automatically sent based on the contents of $_POST['trackbacks'].
         * Most of the $_POST variables will fall back gracefully if they don't exist, e.g. if they're posting from the Bookmarklet.
         *
         * Calls the add_post trigger with the inserted post and extra options.
         *
         * Parameters:
         *     $values - The data to insert.
         *     $clean - The sanitized URL (or empty to default to "(feather).(new post's id)").
         *     $url - The unique URL (or empty to default to "(feather).(new post's id)").
         *     $feather - The feather to post as.
{'fraction_non_alphanumeric': 0.1571320182094082, 'fraction_numerical': 0.0040212443095599395, 'mean_word_length': 1.407928388746803, 'pattern_counts': {'":': 2, '<': 11, '<?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': 62, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6475790', 'n_tokens_mistral': 3422, 'n_tokens_neox': 3277, 'n_words': 742}