<commit_before><?php
    class Photo extends Feathers implements Feather {
        public function __init() {
            $this->setField(array("attr" => "title",
                                  "type" => "text",
                                  "label" => __("Title", "photo"),
                                  "optional" => true));
            $this->setField(array("attr" => "photo",
                                  "type" => "file",
                                  "label" => __("Photo", "photo"),
                                  "multiple" => false,
                                  "note" => _f("(Max. file size: %d Megabytes)", Config::current()->uploads_limit, "photo")));
            $this->setField(array("attr" => "caption",
                                  "type" => "text_block",
                                  "label" => __("Caption", "photo"),
                                  "optional" => true,
                                  "preview" => true));

            $this->setFilter("title", array("markup_post_title", "markup_title"));
            $this->setFilter("caption", array("markup_post_text", "markup_text"));

            $this->respondTo("delete_post", "delete_file");
            $this->respondTo("post_options", "add_option");
        }

        public function submit() {
            if (isset($_FILES['photo']) and upload_tester($_FILES['photo']))
                $filename = upload($_FILES['photo'], array("jpg", "jpeg", "png", "gif", "tif", "tiff", "bmp"));
            else
                error(__("Error"), __("You did not select a photo to upload.", "photo"), null, 422);
                
            if (!empty($_POST['option']['source']) and is_url($_POST['option']['source']))
                $_POST['option']['source'] = add_scheme($_POST['option']['source']);

            fallback($_POST['title'], "");
            fallback($_POST['caption'], "");
            fallback($_POST['slug'], $_POST['title']);

            return Post::add(array("title" => $_POST['title'],
                                   "filename" => $filename,
                                   "caption" => $_POST['caption']));
        }

        public function update($post) {
            if (isset($_FILES['photo']) and upload_tester($_FILES['photo'])) {
                $this->delete_file($post);
                $filename = upload($_FILES['photo'], array("jpg", "jpeg", "png", "gif", "tif", "tiff", "bmp"));
            } else
                $filename = $post->filename;

            if (!empty($_POST['option']['source']) and is_url($_POST['option']['source']))
                $_POST['option']['source'] = add_scheme($_POST['option']['source']);

            fallback($_POST['title'], "");
            fallback($_POST['caption'], "");

            return $post->update(array("title" => $_POST['title'],
                                       "filename" => $filename,
                                       "caption" => $_POST['caption']));
        }

        public function title($post) {
            return oneof($post->title, $post->title_from_excerpt());
        }

        public function excerpt($post) {
            return $post->caption;
        }

        public function feed_content($post) {
            return '<img src="'.Config::current()->chyrp_url."/includes/thumb.php?file=".urlencode($post->filename).
                   '" alt="'.fix(oneof($post->alt_text, $post->filename), true).'"><p>'.$post->caption.'</p>';
        }

        public function delete_file($post) {
            if ($post->feather != "photo")
                return;

            $trigger = Trigger::current();
            $filepath = uploaded($post->filename, false);
<commit_msg>Photo feather: improved feed_content()<commit_after><?php
    class Photo extends Feathers implements Feather {
        public function __init() {
            $this->setField(array("attr" => "title",
                                  "type" => "text",
                                  "label" => __("Title", "photo"),
                                  "optional" => true));
            $this->setField(array("attr" => "photo",
                                  "type" => "file",
                                  "label" => __("Photo", "photo"),
                                  "multiple" => false,
                                  "note" => _f("(Max. file size: %d Megabytes)", Config::current()->uploads_limit, "photo")));
            $this->setField(array("attr" => "caption",
                                  "type" => "text_block",
                                  "label" => __("Caption", "photo"),
                                  "optional" => true,
                                  "preview" => true));

            $this->setFilter("title", array("markup_post_title", "markup_title"));
            $this->setFilter("caption", array("markup_post_text", "markup_text"));

            $this->respondTo("delete_post", "delete_file");
            $this->respondTo("post_options", "add_option");
        }

        public function submit() {
            if (isset($_FILES['photo']) and upload_tester($_FILES['photo']))
                $filename = upload($_FILES['photo'], array("jpg", "jpeg", "png", "gif", "tif", "tiff", "bmp"));
            else
                error(__("Error"), __("You did not select a photo to upload.", "photo"), null, 422);
                
            if (!empty($_POST['option']['source']) and is_url($_POST['option']['source']))
                $_POST['option']['source'] = add_scheme($_POST['option']['source']);

            fallback($_POST['title'], "");
            fallback($_POST['caption'], "");
            fallback($_POST['slug'], $_POST['title']);

            return Post::add(array("title" => $_POST['title'],
                                   "filename" => $filename,
                                   "caption" => $_POST['caption']));
        }

        public function update($post) {
            if (isset($_FILES['photo']) and upload_tester($_FILES['photo'])) {
                $this->delete_file($post);
                $filename = upload($_FILES['photo'], array("jpg", "jpeg", "png", "gif", "tif", "tiff", "bmp"));
            } else
                $filename = $post->filename;

            if (!empty($_POST['option']['source']) and is_url($_POST['option']['source']))
                $_POST['option']['source'] = add_scheme($_POST['option']['source']);

            fallback($_POST['title'], "");
            fallback($_POST['caption'], "");

            return $post->update(array("title" => $_POST['title'],
                                       "filename" => $filename,
                                       "caption" => $_POST['caption']));
        }

        public function title($post) {
            return oneof($post->title, $post->title_from_excerpt());
        }

        public function excerpt($post) {
            return $post->caption;
        }

        public function feed_content($post) {
            $content = '<img src="'.Config::current()->chyrp_url."/includes/thumb.php?file=".urlencode($post->filename).
                       '" alt="'.fix(oneof($post->alt_text, $post->filename), true).'">';

            if (!empty($post->caption))
                $content.= "<p>".$post->caption."</p>";

            return $content;
        }

        public function delete_file($post) {
            if ($post->feather != "photo")
                return;

            $trigger = Trigger::current();
            $filepath = uploaded($post->filename, false);

{'fraction_non_alphanumeric': 0.1853030905955697, 'fraction_numerical': 0.0007958615200955034, 'mean_word_length': 1.6861417883861773, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 92, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 30, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '204848', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1857, 'n_words': 349}