<commit_before><?php
/**
 * \Elabftw\Elabftw\Import
 *
 * @author <NAME> <<EMAIL>>
 * @copyright 2012 <NAME>
 * @see http://www.elabftw.net Official website
 * @license AGPL-3.0
 * @package elabftw
 */
namespace Elabftw\Elabftw;

use \Exception;

/**
 * Mother class of ImportCsv and ImportZip
 */
abstract class Import
{
    /**
     * Read the file input
     *
     * @return void
     */
    abstract protected function openFile();

    /**
     * Get the temporary uploaded file
     *
     * @return string a sha512 hash of uniqid()
     */
    protected function getFilePath()
    {
        return $_FILES['file']['tmp_name'];
    }

    /**
     * Get what type we want
     *
     * @return int The type of item
     */
    protected function getTarget()
    {
        if (isset($_COOKIE['itemType']) && is_pos_int($_COOKIE['itemType'])) {
            return $_COOKIE['itemType'];
        }
        throw new Exception('No cookies found. Import aborted.');
    }

    /**
     * Try to read the file we have
     *
     * @throws Exception if cannot read the file
     * @return bool
     */
    protected function checkFileReadable()
    {
        if (is_readable($_FILES['file']['tmp_name'])) {
            return true;
        }
        throw new Exception(_("Could not open the file."));
    }

    /**
     * Look at mime type. not a trusted source, but it can prevent dumb errors
     * There is null in the mimes array because it can happen that elabftw files are like that.
     *
     * @throws Exception if the mime type is not whitelisted
     * @return bool
     */
    protected function checkMimeType()
    {
        $mimes = array(null, 'application/vnd.ms-excel', 'text/plain',
            'text/csv', 'text/tsv',
            'application/zip', 'application/force-download', 'application/x-zip-compressed');

        if (in_array($_FILES['file']['type'], $mimes)) {
            return true;<commit_msg>add application/ziproot to list of good mimetypes. fix #235<commit_after><?php
/**
 * \Elabftw\Elabftw\Import
 *
 * @author <NAME> <<EMAIL>>
 * @copyright 2012 <NAME>
 * @see http://www.elabftw.net Official website
 * @license AGPL-3.0
 * @package elabftw
 */
namespace Elabftw\Elabftw;

use \Exception;

/**
 * Mother class of ImportCsv and ImportZip
 */
abstract class Import
{
    /**
     * Read the file input
     *
     * @return void
     */
    abstract protected function openFile();

    /**
     * Get the temporary uploaded file
     *
     * @return string a sha512 hash of uniqid()
     */
    protected function getFilePath()
    {
        return $_FILES['file']['tmp_name'];
    }

    /**
     * Get what type we want
     *
     * @return int The type of item
     */
    protected function getTarget()
    {
        if (isset($_COOKIE['itemType']) && is_pos_int($_COOKIE['itemType'])) {
            return $_COOKIE['itemType'];
        }
        throw new Exception('No cookies found. Import aborted.');
    }

    /**
     * Try to read the file we have
     *
     * @throws Exception if cannot read the file
     * @return bool
     */
    protected function checkFileReadable()
    {
        if (is_readable($_FILES['file']['tmp_name'])) {
            return true;
        }
        throw new Exception(_("Could not open the file."));
    }

    /**
     * Look at mime type. not a trusted source, but it can prevent dumb errors
     * There is null in the mimes array because it can happen that elabftw files are like that.
     *
     * @throws Exception if the mime type is not whitelisted
     * @return bool
     */
    protected function checkMimeType()
    {
        $mimes = array(null, 'application/vnd.ms-excel', 'text/plain',
            'text/csv', 'text/tsv',
            'application/zip', 'application/force-download', 'application/x-zip-compressed', 'application/ziproot');

        if (in_array($_FILES['file']['type'], $mimes)) {
            return true;
{'fraction_non_alphanumeric': 0.1271985725210298, 'fraction_numerical': 0.005353046138159572, 'mean_word_length': 2.2402972749793557, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6849850', 'n_tokens_mistral': 1198, 'n_tokens_neox': 1162, 'n_words': 352}