Classes

File phpboost/config/FileUploadConfig.class.php

File phpboost/config/FileUploadConfig.class.php

  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 
<?php
/**
 * @package     PHPBoost
 * @subpackage  Config
 * @copyright   &copy; 2005-2019 PHPBoost
 * @license     https://www.gnu.org/licenses/gpl-3.0.html GNU/GPL-3.0
 * @author      Kevin MASSY <reidlos@phpboost.com>
 * @version     PHPBoost 5.2 - last update: 2016 12 14
 * @since       PHPBoost 3.0 - 2010 08 09
 * @contributor Julien BRISWALTER <j1.seth@phpboost.com>
 * @contributor Sebastien LARTIGUE <babsolune@phpboost.com>
*/

class FileUploadConfig extends AbstractConfigData
{
    const AUTHORIZATION_ENABLE_INTERFACE_FILES = 'authorization_enable_interface_files';
    const MAXIMUM_SIZE_UPLOAD = 'maximum_size_upload';
    const ENABLE_BANDWIDTH_PROTECTION = 'enable_bandwidth_protect';
    const DISPLAY_FILE_THUMBNAIL = 'display_file_thumbnail';
    const AUTHORIZED_EXTENSIONS = 'authorized_extensions';
    const AUTH_FILES_BIT = 0x01;

    public function get_authorization_enable_interface_files()
    {
        return $this->get_property(self::AUTHORIZATION_ENABLE_INTERFACE_FILES);
    }

    public function set_authorization_enable_interface_files(array $array)
    {
        $this->set_property(self::AUTHORIZATION_ENABLE_INTERFACE_FILES, $array);
    }

    public function is_authorized_to_access_interface_files()
    {
        return AppContext::get_current_user()->check_auth($this->get_authorization_enable_interface_files(), FileUploadConfig::AUTH_FILES_BIT);
    }

    public function get_maximum_size_upload()
    {
        return $this->get_property(self::MAXIMUM_SIZE_UPLOAD);
    }

    public function set_maximum_size_upload($size)
    {
        $this->set_property(self::MAXIMUM_SIZE_UPLOAD, $size);
    }

    public function get_enable_bandwidth_protect()
    {
        return $this->get_property(self::ENABLE_BANDWIDTH_PROTECTION);
    }

    public function set_enable_bandwidth_protect($value)
    {
        $this->set_property(self::ENABLE_BANDWIDTH_PROTECTION, $value);
    }

    public function get_display_file_thumbnail()
    {
        return $this->get_property(self::DISPLAY_FILE_THUMBNAIL);
    }

    public function set_display_file_thumbnail($value)
    {
        $this->set_property(self::DISPLAY_FILE_THUMBNAIL, $value);
    }

    public function get_authorized_extensions()
    {
        return $this->get_property(self::AUTHORIZED_EXTENSIONS);
    }

    public function set_authorized_extensions(array $array)
    {
        $this->set_property(self::AUTHORIZED_EXTENSIONS, $array);
    }

    public function get_authorized_picture_extensions()
    {
        $pictures_extensions = array('jpg', 'jpeg', 'bmp', 'gif', 'png');
        $authorized_pictures_extensions = array();

        foreach ($pictures_extensions as $extension)
        {
            if (in_array($extension, $this->get_authorized_extensions()))
                $authorized_pictures_extensions[] = $extension;
        }

        return $authorized_pictures_extensions;
    }

    public function get_default_values()
    {
        return array(
            self::AUTHORIZATION_ENABLE_INTERFACE_FILES => array('r0' => 1, 'r1' => 1),
            self::MAXIMUM_SIZE_UPLOAD => 512,
            self::ENABLE_BANDWIDTH_PROTECTION => true,
            self::DISPLAY_FILE_THUMBNAIL => true,
            self::AUTHORIZED_EXTENSIONS => array(
                'jpg', 'jpeg', 'bmp', 'gif', 'png', 'tif', 'svg', 'ico', 'nef',
                'rar', 'zip', 'gz', '7z',
                'txt', 'doc', 'docx', 'pdf', 'ppt', 'xls', 'odt', 'odp', 'ods', 'odg', 'odc', 'odf', 'odb', 'xcf', 'csv',
                'flv', 'mp3','ogg', 'mpg', 'mov','swf', 'wav', 'wmv', 'midi', 'mng', 'qt', 'mp4', 'mkv',
                'ttf', 'tex', 'rtf', 'psd', 'iso'
            )
        );
    }

    /**
     * Returns the configuration.
     * @return FileUploadConfig
     */
    public static function load()
    {
        return ConfigManager::load(__CLASS__, 'kernel', 'file-upload-config');
    }

    /**
     * Saves the configuration in the database. Has it become persistent.
     */
    public static function save()
    {
        ConfigManager::save('kernel', self::load(), 'file-upload-config');
    }
}
?>