Beispiel #1
0
 /**
  * Decodes unreserved chars encoded by PHP's ``urlencode()``, deeply.
  *
  * For further details regarding unreserved chars, see: {@link http://www.faqs.org/rfcs/rfc3986.html}.
  *
  * @package optimizeMember\Utilities
  * @since 111017
  *
  * @see http://www.faqs.org/rfcs/rfc3986.html
  *
  * @param str|array $value Either a string, an array, or a multi-dimensional array, filled with integer and/or string values.
  * @return str|array Either the input string, or the input array; after all unreserved chars are decoded properly.
  */
 public static function urldecode_ur_chars_deep($value = array())
 {
     if (is_array($value)) {
         foreach ($value as &$r) {
             /* Reference. */
             $r = c_ws_plugin__optimizemember_utils_strings::urldecode_ur_chars_deep($r);
         }
         return $value;
         /* Return modified array. */
     }
     return str_replace(array("%2D", "%2E", "%5F", "%7E"), array("-", ".", "_", "~"), (string) $value);
 }
Beispiel #2
0
 /**
  * Creates an Amazon CloudFront RSA-SHA1 signature URL.
  *
  * @package optimizeMember\Files
  * @since 110926
  *
  * @param str $file Input file path, to be signed by this routine.
  * @param bool $stream Is this resource file to be served as streaming media?
  * @param bool $inline Is this resource file to be served inline, or no?
  * @param bool $ssl Is this resource file to be served via SSL, or no?
  * @param str $basename The absolute basename of the resource file.
  * @param str $mimetype The MIME content-type of the resource file.
  * @return str An RSA-SHA1 signature URL for Amazon CloudFront.
  */
 public static function amazon_cf_url($file = FALSE, $stream = FALSE, $inline = FALSE, $ssl = FALSE, $basename = FALSE, $mimetype = FALSE)
 {
     $file = trim((string) $file, "/");
     $url_e_file = c_ws_plugin__optimizemember_utils_strings::urldecode_ur_chars_deep(urlencode($file));
     /**/
     foreach ($GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"] as $option => $option_value) {
         if (preg_match("/^amazon_cf_files_/", $option) && ($option = preg_replace("/^amazon_cf_files_/", "", $option))) {
             $cfc[$option] = $option_value;
         }
     }
     /**/
     $cfc["expires"] = strtotime("+" . apply_filters("ws_plugin__optimizemember_amazon_cf_file_expires_time", "24 hours", get_defined_vars()));
     /**/
     $cf_extn = strtolower(substr($file, strrpos($file, ".") + 1));
     $cf_ip_res = c_ws_plugin__optimizemember_utils_conds::is_localhost() ? false : true;
     $cf_stream_extn_resource_exclusions = array_unique((array) apply_filters("ws_plugin__optimizemember_amazon_cf_file_streaming_extension_resource_exclusions", array("mp3"), get_defined_vars()));
     $cf_resource = $stream ? in_array($cf_extn, $cf_stream_extn_resource_exclusions) ? substr($file, 0, strrpos($file, ".")) : $file : "http" . ($ssl ? "s" : "") . "://" . ($cfc["distro_downloads_cname"] ? $cfc["distro_downloads_cname"] : $cfc["distro_downloads_dname"]) . "/" . $url_e_file;
     $cf_url = $stream ? "rtmp" . ($ssl ? "e" : "") . "://" . ($cfc["distro_streaming_cname"] ? $cfc["distro_streaming_cname"] : $cfc["distro_streaming_dname"]) . "/cfx/st/" . $file : "http" . ($ssl ? "s" : "") . "://" . ($cfc["distro_downloads_cname"] ? $cfc["distro_downloads_cname"] : $cfc["distro_downloads_dname"]) . "/" . $url_e_file;
     $cf_policy = '{"Statement":[{"Resource":"' . c_ws_plugin__optimizemember_utils_strings::esc_dq($cf_resource) . '","Condition":{' . ($cf_ip_res ? '"IpAddress":{"AWS:SourceIp":"' . c_ws_plugin__optimizemember_utils_strings::esc_dq($_SERVER["REMOTE_ADDR"]) . '/32"},' : '') . '"DateLessThan":{"AWS:EpochTime":' . (int) $cfc["expires"] . '}}}]}';
     /**/
     $cf_signature = c_ws_plugin__optimizemember_files_in::amazon_cf_rsa_sign($cf_policy);
     $cf_base64_url_safe_policy = c_ws_plugin__optimizemember_utils_strings::base64_url_safe_encode($cf_policy, array("+", "=", "/"), array("-", "_", "~"), false);
     $cf_base64_url_safe_signature = c_ws_plugin__optimizemember_utils_strings::base64_url_safe_encode($cf_signature, array("+", "=", "/"), array("-", "_", "~"), false);
     /**/
     return add_query_arg(c_ws_plugin__optimizemember_utils_strings::urldecode_ur_chars_deep(urlencode_deep(array("Policy" => $cf_base64_url_safe_policy, "Signature" => $cf_base64_url_safe_signature, "Key-Pair-Id" => $cfc["private_key_id"]))), $cf_url);
 }