File "class-wc-product-download.php"

Full path: /home/kosmetik/public_html/wp-content/plugins/woocommerce/includes/class-wc-product-download.php
File size: 4.47 B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php

defined('ABSPATH') || exit;
class WC_Product_Download implements ArrayAccess
{
    protected $data = array('id' => '', 'name' => '', 'file' => '');
    public function get_data()
    {
        return $this->data;
    }
    public function get_allowed_mime_types()
    {
        return apply_filters('woocommerce_downloadable_file_allowed_mime_types', get_allowed_mime_types());
    }
    public function get_type_of_file_path($file_path = '')
    {
        $file_path = $file_path ? $file_path : $this->get_file();
        $parsed_url = parse_url($file_path);
        if ($parsed_url && isset($parsed_url['host']) && (!isset($parsed_url['scheme']) || in_array($parsed_url['scheme'], array('http', 'https')))) {
            return 'absolute';
        } elseif ('[' === substr($file_path, 0, 1) && ']' === substr($file_path, -1)) {
            return 'shortcode';
        } else {
            return 'relative';
        }
    }
    public function get_file_type()
    {
        $type = wp_check_filetype(strtok($this->get_file(), '?'), $this->get_allowed_mime_types());
        return $type['type'];
    }
    public function get_file_extension()
    {
        $parsed_url = wp_parse_url($this->get_file(), PHP_URL_PATH);
        return pathinfo($parsed_url, PATHINFO_EXTENSION);
    }
    public function is_allowed_filetype()
    {
        $file_path = $this->get_file();
        $is_file_on_server = false;
        if (false !== stripos($file_path, network_site_url('/', 'https')) || false !== stripos($file_path, network_site_url('/', 'http')) || false !== stripos($file_path, site_url('/', 'https')) || false !== stripos($file_path, site_url('/', 'http'))) {
            $is_file_on_server = true;
        }
        if (!$is_file_on_server && 'relative' !== $this->get_type_of_file_path()) {
            return true;
        }
        return !$this->get_file_extension() || in_array($this->get_file_type(), $this->get_allowed_mime_types(), true);
    }
    public function file_exists()
    {
        if ('relative' !== $this->get_type_of_file_path()) {
            return true;
        }
        $file_url = $this->get_file();
        if ('..' === substr($file_url, 0, 2) || '/' !== substr($file_url, 0, 1)) {
            $file_url = realpath(ABSPATH . $file_url);
        } elseif (substr(WP_CONTENT_DIR, strlen(untrailingslashit(ABSPATH))) === substr($file_url, 0, strlen(substr(WP_CONTENT_DIR, strlen(untrailingslashit(ABSPATH)))))) {
            $file_url = realpath(WP_CONTENT_DIR . substr($file_url, 11));
        }
        return apply_filters('woocommerce_downloadable_file_exists', file_exists($file_url), $this->get_file());
    }
    public function set_id($value)
    {
        $this->data['id'] = wc_clean($value);
    }
    public function set_name($value)
    {
        $this->data['name'] = wc_clean($value);
    }
    public function set_previous_hash($value)
    {
        wc_deprecated_function(__FUNCTION__, '3.3');
        $this->data['previous_hash'] = wc_clean($value);
    }
    public function set_file($value)
    {
        if (preg_match('#^//+(/[^/].+)$#i', $value, $matches)) {
            $value = $matches[1];
        }
        switch ($this->get_type_of_file_path($value)) {
            case 'absolute':
                $this->data['file'] = esc_url_raw($value);
                break;
            default:
                $this->data['file'] = wc_clean($value);
                break;
        }
    }
    public function get_id()
    {
        return $this->data['id'];
    }
    public function get_name()
    {
        return $this->data['name'];
    }
    public function get_previous_hash()
    {
        wc_deprecated_function(__FUNCTION__, '3.3');
        return $this->data['previous_hash'];
    }
    public function get_file()
    {
        return $this->data['file'];
    }
    public function offsetGet($offset)
    {
        switch ($offset) {
            default:
                if (is_callable(array($this, "get_{$offset}"))) {
                    return $this->{"get_{$offset}"}();
                }
                break;
        }
        return '';
    }
    public function offsetSet($offset, $value)
    {
        switch ($offset) {
            default:
                if (is_callable(array($this, "set_{$offset}"))) {
                    return $this->{"set_{$offset}"}($value);
                }
                break;
        }
    }
    public function offsetUnset($offset)
    {
    }
    public function offsetExists($offset)
    {
        return in_array($offset, array_keys($this->data), true);
    }
}