/** * Handles Download Access permissions. * * @package s2Member\Files * @since 110524RC * * @attaches-to ``add_action('init');`` * @also-called-by API Function {@link s2Member\API_Functions\s2member_file_download_url()}, w/ ``$create_file_download_url`` param. * * @param array $create_file_download_url Optional. If this function is called directly, we can pass arguments through this array. * Possible array elements: `file_download` *(required)*, `file_download_key`, `file_stream`, `file_inline`, `file_storage`, `file_remote`, `file_ssl`, `file_rewrite`, `file_rewrite_base`, `skip_confirmation`, `url_to_storage_source`, `count_against_user`, `check_user`. * * @return null|string If called directly with ``$create_file_download_url``, returns a string with the URL, based on configuration. * Else, this function may exit script execution after serving a File Download. */ public static function check_file_download_access($create_file_download_url = NULL) { if (is_array($create_file_download_url) || !empty($_GET['s2member_file_download'])) { return c_ws_plugin__s2member_files_in::check_file_download_access($create_file_download_url); } return NULL; // Default return value. }
/** * Generates a File Download URL for access to a file protected by s2Member. * * @package s2Member\Files * @since 110926 * * @param array $config Required. This is an array of configuration options associated with permissions being checked against the current User/Member; and also the actual URL generated by this routine. * Possible ``$config`` array elements: `file_download` *(required)*, `file_download_key`, `file_stream`, `file_inline`, `file_storage`, `file_remote`, `file_ssl`, `file_rewrite`, `file_rewrite_base`, `skip_confirmation`, `url_to_storage_source`, `count_against_user`, `check_user`. * @param bool $get_streamer_array Optional. Defaults to `false`. If `true`, this function will return an array with the following elements: `streamer`, `file`, `url`. For further details, please review this section in your Dashboard: `s2Member → Download Options → JW Player & RTMP Protocol Examples`. * * @return string A File Download URL string on success; or an array on success, with elements `streamer`, `file`, `url` when/if ``$get_streamer_array`` is true; else false on any type of failure. * * @see s2Member\API_Functions\s2member_file_download_url() */ public static function create_file_download_url($config = array(), $get_streamer_array = FALSE) { foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_before_create_file_download_url', get_defined_vars()); unset($__refs, $__v); // Housekeeping. $config = is_array($config) ? $config : array(); // This absolutely MUST be an array. $config['file_download'] = isset($config['file_download']) && is_string($config['file_download']) ? trim($config['file_download'], '/') : ''; $config['file_download_key'] = !empty($config['file_download_key']) && is_string($config['file_download']) ? c_ws_plugin__s2member_files::file_download_key($config['file_download'], in_array($config['file_download_key'], array('ip-forever', 'universal', 'cache-compatible')) ? $config['file_download_key'] : FALSE) : ''; $config['url_to_storage_source'] = $get_streamer_array ? TRUE : @$config['url_to_storage_source']; // Force a streaming URL here via ``$get_streamer_array``? $config['file_stream'] = $get_streamer_array ? TRUE : @$config['file_stream']; // Force a streaming URL here via ``$get_streamer_array``? if ($url_ = c_ws_plugin__s2member_files_in::check_file_download_access($config)) { foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action('ws_plugin__s2member_during_create_file_download_url', get_defined_vars()); unset($__refs, $__v); // Housekeeping. $extension = strtolower(substr($config['file_download'], strrpos($config['file_download'], '.') + 1)); $streaming = isset($config['file_stream']) ? filter_var($config['file_stream'], FILTER_VALIDATE_BOOLEAN) : (in_array($extension, preg_split('/[' . "\r\n\t" . '\\s;,]+/', $GLOBALS['WS_PLUGIN__']['s2member']['o']['file_download_stream_extensions'])) ? TRUE : FALSE); $ssl = isset($config['file_ssl']) ? filter_var($config['file_ssl'], FILTER_VALIDATE_BOOLEAN) : (is_ssl() ? TRUE : FALSE); if ($get_streamer_array && $streaming && ($cfx = '/cfx/st') && ($cfx_pos = strpos($url_, $cfx)) !== FALSE && ($streamer = substr($url_, 0, $cfx_pos + strlen($cfx))) && ($url = c_ws_plugin__s2member_files_in::check_file_download_access(array_merge($config, array('file_stream' => FALSE, 'check_user' => FALSE, 'count_against_user' => FALSE))))) { $return = array('streamer' => $streamer, 'prefix' => $extension . ':', 'file' => preg_replace('/^' . preg_quote($streamer, '/') . '\\//', '', $url_), 'url' => preg_replace('/^.+?\\:/', $ssl ? 'https:' : 'http:', $url)); } else { if ($get_streamer_array && $streaming && is_array($ups = c_ws_plugin__s2member_utils_urls::parse_url($url_)) && isset($ups['scheme'], $ups['host']) && ($streamer = $ups['scheme'] . '://' . $ups['host'] . (!empty($ups['port']) ? ':' . $ups['port'] : '')) && ($url = c_ws_plugin__s2member_files_in::check_file_download_access(array_merge($config, array('file_stream' => FALSE, 'check_user' => FALSE, 'count_against_user' => FALSE))))) { $return = array('streamer' => $streamer, 'prefix' => '', 'file' => preg_replace('/^' . preg_quote($streamer, '/') . '\\//', '', $url_), 'url' => preg_replace('/^.+?\\:/', $ssl ? 'https:' : 'http:', $url)); } else { if ($get_streamer_array) { // If streamer, we MUST return false here; unable to acquire streamer/file. $return = FALSE; } else { // Else return URL string ( ``$get_streamer_array`` is false ). $return = $url_; } } } // Else return URL string. } return apply_filters('ws_plugin__s2member_create_file_download_url', isset($return) ? $return : FALSE, get_defined_vars()); }
/** * Handles Download Access permissions. * * @package s2Member\Files * @since 110524RC * * @attaches-to ``add_action("init");`` * @also-called-by API Function {@link s2Member\API_Functions\s2member_file_download_url()}, w/ ``$create_file_download_url`` param. * * @param array $create_file_download_url Optional. If this function is called directly, we can pass arguments through this array. * Possible array elements: `file_download` *(required)*, `file_download_key`, `file_stream`, `file_inline`, `file_storage`, `file_remote`, `file_ssl`, `file_rewrite`, `file_rewrite_base`, `skip_confirmation`, `url_to_storage_source`, `count_against_user`, `check_user`. * @return null|str If called directly with ``$create_file_download_url``, returns a string with the URL, based on configuration. * Else, this function may exit script execution after serving a File Download. */ public static function check_file_download_access($create_file_download_url = FALSE) { if (is_array($create_file_download_url) || !empty($_GET["s2member_file_download"])) { return c_ws_plugin__s2member_files_in::check_file_download_access($create_file_download_url); } }
/** * Generates a File Download URL for access to a file protected by s2Member. * * @package s2Member\Files * @since 110926 * * @param array $config Required. This is an array of configuration options associated with permissions being checked against the current User/Member; and also the actual URL generated by this routine. * Possible ``$config`` array elements: `file_download` *(required)*, `file_download_key`, `file_stream`, `file_inline`, `file_storage`, `file_remote`, `file_ssl`, `file_rewrite`, `file_rewrite_base`, `skip_confirmation`, `url_to_storage_source`, `count_against_user`, `check_user`. * @param bool $get_streamer_array Optional. Defaults to `false`. If `true`, this function will return an array with the following elements: `streamer`, `file`, `url`. For further details, please review this section in your Dashboard: `s2Member -› Download Options -› JW Player & RTMP Protocol Examples`. * @return str A File Download URL string on success; or an array on success, with elements `streamer`, `file`, `url` when/if ``$get_streamer_array`` is true; else false on any type of failure. * * @see s2Member\API_Functions\s2member_file_download_url() */ public static function create_file_download_url($config = FALSE, $get_streamer_array = FALSE) { foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_before_create_file_download_url", get_defined_vars()); unset($__refs, $__v); $config = is_array($config) ? $config : array(); $config["file_download"] = isset($config["file_download"]) && is_string($config["file_download"]) ? trim($config["file_download"], "/") : @$config["file_download"]; $config["file_download_key"] = isset($config["file_download"]) && is_string($config["file_download"]) && !empty($config["file_download_key"]) ? c_ws_plugin__s2member_files::file_download_key($config["file_download"], in_array($config["file_download_key"], array("ip-forever", "universal", "cache-compatible")) ? $config["file_download_key"] : false) : @$config["file_download_key"]; $config["url_to_storage_source"] = $get_streamer_array ? true : @$config["url_to_storage_source"]; $config["file_stream"] = $get_streamer_array ? true : @$config["file_stream"]; if ($_url = c_ws_plugin__s2member_files_in::check_file_download_access($create_file_download_url = $config)) { foreach (array_keys(get_defined_vars()) as $__v) { $__refs[$__v] =& ${$__v}; } do_action("ws_plugin__s2member_during_create_file_download_url", get_defined_vars()); unset($__refs, $__v); $extension = strtolower(substr($config["file_download"], strrpos($config["file_download"], ".") + 1)); $streaming = isset($config["file_stream"]) ? filter_var($config["file_stream"], FILTER_VALIDATE_BOOLEAN) : (in_array($extension, preg_split("/[\r\n\t\\s;,]+/", $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["file_download_stream_extensions"])) ? true : false); $ssl = isset($config["file_ssl"]) ? filter_var($config["file_ssl"], FILTER_VALIDATE_BOOLEAN) : (is_ssl() ? true : false); if ($get_streamer_array && $streaming && ($cfx = "/cfx/st") && ($cfx_pos = strpos($_url, $cfx)) !== false && ($streamer = substr($_url, 0, $cfx_pos + strlen($cfx))) && ($url = c_ws_plugin__s2member_files_in::check_file_download_access(array_merge($config, array("file_stream" => false, "check_user" => false, "count_against_user" => false))))) { $return = array("streamer" => $streamer, "prefix" => $extension . ":", "file" => preg_replace("/^" . preg_quote($streamer, "/") . "\\//", "", $_url), "url" => preg_replace("/^.+?\\:/", $ssl ? "https:" : "http:", $url)); } else { if ($get_streamer_array && $streaming && is_array($ups = c_ws_plugin__s2member_utils_urls::parse_url($_url)) && isset($ups["scheme"], $ups["host"]) && ($streamer = $ups["scheme"] . "://" . $ups["host"] . (!empty($ups["port"]) ? ":" . $ups["port"] : "")) && ($url = c_ws_plugin__s2member_files_in::check_file_download_access(array_merge($config, array("file_stream" => false, "check_user" => false, "count_against_user" => false))))) { $return = array("streamer" => $streamer, "prefix" => $extension . ":", "file" => preg_replace("/^" . preg_quote($streamer, "/") . "\\//", "", $_url), "url" => preg_replace("/^.+?\\:/", $ssl ? "https:" : "http:", $url)); } else { if ($get_streamer_array) { $return = false; } else { // Else return URL string ( ``$get_streamer_array`` is false ). $return = $_url; } } } } return apply_filters("ws_plugin__s2member_create_file_download_url", isset($return) ? $return : false, get_defined_vars()); }