<commit_before><?php
/**
 * Содержит класс FileRepoInfo
 *
 * @package energine
 * @subpackage kernel
 * @author d.pavka
 * @copyright <EMAIL>
 */

/**
 * Альтернативный FileInfo
 *
 * @package energine
 * @subpackage kernel
 * @author <EMAIL>
 */
class FileRepoInfo extends DBWorker {
    /**
     * Мета тип image
     */
    const META_TYPE_IMAGE = 'image';
    /**
     * Мета тип видео
     */
    const META_TYPE_VIDEO = 'video';
    /**
     * Мета тип audio
     */
    const META_TYPE_AUDIO = 'audio';
    /**
     * Мета тип zip
     */
    const META_TYPE_ZIP = 'zip';

    const META_TYPE_TEXT = 'text';
    /**
     * Мета тип папка
     */
    const META_TYPE_FOLDER = 'folder';

    const META_TYPE_UNKNOWN = 'unknown';

    /**
     * Finfo object
     *
     * @access private
     * @var Fileinfo
     */
    private $finfo;
    /**
     * @var PDOStatement
     */
    private $getFInfoSQL;

    /**
     * Конструктор класса
     *
     * @access public
     */
    public function __construct() {
        parent::__construct();
        $this->finfo = new finfo(FILEINFO_MIME_TYPE);
        $this->getFInfoSQL = $this->dbh->getPDO()->prepare('SELECT upl_internal_type as type, upl_mime_type as mime, upl_width as width, upl_height as height, upl_is_mp4 as is_mp4, upl_is_webm as is_webm, upl_is_flv as is_flv FROM share_uploads WHERE upl_path = ?');
    }

    /**
     * @param $filename
     * @param bool $forceReadFromFile
     * @return mixed|object
     * @throws Exception
     */
    public function analyze($filename, $forceReadFromFile = false) {
        try {
            if (
                $forceReadFromFile
                ||
                !$this->getFInfoSQL->execute(array($filename))
                ||
                !($result = $this->getFInfoSQL->fetch(PDO::FETCH_ASSOC))
            ) {
                if(!($result = $this->getFileInfoData($filename)))
                    throw new Exception();
            }
        } catch (Exception $e) {
            $result['type'] = self::META_TYPE_UNKNOWN;
            $result['mime'] = 'unknown/mime-type';
            $result['width'] = null;
            $result['height'] = null;
            $result['is_flv'] = false;
            $result['is_webm'] = false;
            $result['is_mp4'] = false;
        }

        return (object)$result;
    }

    /**
     * @param $filename
     * @return mixed
     */
    private function getFileInfoData($filename) {
        $result['width'] = '';
        $result['height'] = '';

        // hotfix для php на продакшне без поддержки https://
        // todo: пофиксить, до выяснения
        if (strpos($filename, 'https://') !== false) {
            $result['mime'] = 'unknown/mime-type';
            $result['type'] = self::META_TYPE_UNKNOWN;
            return $result;
        } elseif (is_dir($filename)) {<commit_msg>Фикс FileRepoInfo - теперь возвращает флаги is_webm, is_flv, is_mp4 для локального файла<commit_after><?php
/**
 * Содержит класс FileRepoInfo
 *
 * @package energine
 * @subpackage kernel
 * @author d.pavka
 * @copyright <EMAIL>
 */

/**
 * Альтернативный FileInfo
 *
 * @package energine
 * @subpackage kernel
 * @author <EMAIL>
 */
class FileRepoInfo extends DBWorker {
    /**
     * Мета тип image
     */
    const META_TYPE_IMAGE = 'image';
    /**
     * Мета тип видео
     */
    const META_TYPE_VIDEO = 'video';
    /**
     * Мета тип audio
     */
    const META_TYPE_AUDIO = 'audio';
    /**
     * Мета тип zip
     */
    const META_TYPE_ZIP = 'zip';

    const META_TYPE_TEXT = 'text';
    /**
     * Мета тип папка
     */
    const META_TYPE_FOLDER = 'folder';

    const META_TYPE_UNKNOWN = 'unknown';

    /**
     * Finfo object
     *
     * @access private
     * @var Fileinfo
     */
    private $finfo;
    /**
     * @var PDOStatement
     */
    private $getFInfoSQL;

    /**
     * Конструктор класса
     *
     * @access public
     */
    public function __construct() {
        parent::__construct();
        $this->finfo = new finfo(FILEINFO_MIME_TYPE);
        $this->getFInfoSQL = $this->dbh->getPDO()->prepare('SELECT upl_internal_type as type, upl_mime_type as mime, upl_width as width, upl_height as height, upl_is_mp4 as is_mp4, upl_is_webm as is_webm, upl_is_flv as is_flv FROM share_uploads WHERE upl_path = ?');
    }

    /**
     * @param $filename
     * @param bool $forceReadFromFile
     * @return mixed|object
     * @throws Exception
     */
    public function analyze($filename, $forceReadFromFile = false) {
        try {
            if (
                $forceReadFromFile
                ||
                !$this->getFInfoSQL->execute(array($filename))
                ||
                !($result = $this->getFInfoSQL->fetch(PDO::FETCH_ASSOC))
            ) {
                if(!($result = $this->getFileInfoData($filename)))
                    throw new Exception();
            }
        } catch (Exception $e) {
            $result['type'] = self::META_TYPE_UNKNOWN;
            $result['mime'] = 'unknown/mime-type';
            $result['width'] = null;
            $result['height'] = null;
            $result['is_flv'] = false;
            $result['is_webm'] = false;
            $result['is_mp4'] = false;
        }

        return (object)$result;
    }

    /**
     * @param $filename
     * @return mixed
     */
    private function getFileInfoData($filename) {
        $result['width'] = '';
        $result['height'] = '';
        $result['is_mp4'] = false;
        $result['is_webm'] = false;
        $result['is_flv'] = false;

        // hotfix для php на продакшне без поддержки https://
        // todo: пофиксить, до выяснения
        if (strpos($filename, 'https://') !== false) {
            $result['mime'] = 'unknown/mime-type';
            $result['type'] = self::META_TYPE_UNKNOWN;
            return $result;
        } elseif (is_dir($filename)) {
{'fraction_non_alphanumeric': 0.13812998472764296, 'fraction_numerical': 0.0013575428474461226, 'mean_word_length': 1.9529058116232465, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1781834', 'n_tokens_mistral': 1953, 'n_tokens_neox': 1947, 'n_words': 390}