<commit_before><?php

require_once($CFG->libdir . '/portfoliolib.php');
require_once($CFG->libdir . '/packer/zip_packer.php');

class portfolio_plugin_download extends portfolio_plugin_pull_base {

    protected $exportconfig;

    public static function get_name() {
        return get_string('pluginname', 'portfolio_download');
    }

    public static function allows_multiple() {
        return false;
    }

    public function expected_time($callertime) {
        return PORTFOLIO_TIME_LOW;
    }

    public function prepare_package() {

        $files = $this->exporter->get_tempfiles();
        $zipper = new zip_packer();

        $filename = 'portfolio-export.zip';
        list ($contextid, $filearea, $itemid) = array_values($this->get('exporter')->get_base_filearea());
        if ($newfile = $zipper->archive_to_storage($files, $contextid, $filearea, $itemid, '/final/', $filename, $this->user->id)) {
            $this->set('file', $newfile);
            return true;
        }
        return false;
    }

    public function send_package() {
        return true;
    }

    public function get_extra_finish_options() {
        global $CFG;
        return array($CFG->wwwroot . '/portfolio/file.php?id=' . $this->exporter->get('id') => get_string('downloadfile', 'portfolio_download'));
    }

    public function verify_file_request_params($params) {
        // for download plugin the only thing we need to verify is that
        // the logged in user is the same as the exporting user
        global $USER;
        if ($USER->id  != $this->user->id) {
            return false;
        }
        return true;
    }

    public function get_continue_url() {
        return false;
    }
}

?><commit_msg>MDL-16414 - make the download plugin just redirect to the file url<commit_after><?php

require_once($CFG->libdir . '/portfoliolib.php');
require_once($CFG->libdir . '/packer/zip_packer.php');

class portfolio_plugin_download extends portfolio_plugin_pull_base {

    protected $exportconfig;

    public static function get_name() {
        return get_string('pluginname', 'portfolio_download');
    }

    public function steal_control($stage) {
        if ($stage == PORTFOLIO_STAGE_FINISHED) {
            return $this->get_base_file_url();
        }
        return false;
    }

    public static function allows_multiple() {
        return false;
    }

    public function expected_time($callertime) {
        return PORTFOLIO_TIME_LOW;
    }

    public function prepare_package() {

        $files = $this->exporter->get_tempfiles();

        if (count($files) == 1) {
            $this->set('file', array_shift($files));
            return true;
        }

        $zipper = new zip_packer();

        $filename = 'portfolio-export.zip';
        list ($contextid, $filearea, $itemid) = array_values($this->get('exporter')->get_base_filearea());
        if ($newfile = $zipper->archive_to_storage($files, $contextid, $filearea, $itemid, '/final/', $filename, $this->user->id)) {
            $this->set('file', $newfile);
            return true;
        }
        return false;
    }

    public function send_package() {
        return true;
    }

    public function verify_file_request_params($params) {
        // for download plugin the only thing we need to verify is that
        // the logged in user is the same as the exporting user
        global $USER;
        if ($USER->id  != $this->user->id) {
            return false;
        }
        return true;
    }

    public function get_continue_url() {
        return false;
    }
}

?>
{'fraction_non_alphanumeric': 0.12625698324022347, 'fraction_numerical': 0.0016759776536312849, 'mean_word_length': 2.549058473736373, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 9, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3494445', 'n_tokens_mistral': 1067, 'n_tokens_neox': 1039, 'n_words': 246}