/** * Handles Download Access permissions. * * @package optimizeMember\Files * @since 110524RC * * @attaches-to ``add_action("init");`` * @also-called-by API Function {@link optimizeMember\API_Functions\optimizemember_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["optimizemember_file_download"])) { return c_ws_plugin__optimizemember_files_in::check_file_download_access($create_file_download_url); } }
/** * Generates a File Download URL for access to a file protected by optimizeMember. * * @package optimizeMember\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: `optimizeMember -> 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 optimizeMember\API_Functions\optimizemember_file_download_url() */ public static function create_file_download_url($config = FALSE, $get_streamer_array = FALSE) { eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_before_create_file_download_url", get_defined_vars()); unset($__refs, $__v); /* Unset defined __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__optimizemember_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__optimizemember_files_in::check_file_download_access($create_file_download_url = $config)) { eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_during_create_file_download_url", get_defined_vars()); unset($__refs, $__v); /* Unset defined __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__"]["optimizemember"]["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__optimizemember_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__optimizemember_utils_urls::parse_url($_url)) && isset($ups["scheme"], $ups["host"]) && ($streamer = $ups["scheme"] . "://" . $ups["host"] . (!empty($ups["port"]) ? ":" . $ups["port"] : "")) && ($url = c_ws_plugin__optimizemember_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__optimizemember_create_file_download_url", isset($return) ? $return : false, get_defined_vars()); }