/** * Generates Specific Post/Page Access links. * * @package optimizeMember\SP_Access * @since 3.5 * * @param str|int $sp_ids Comma-delimited list of Specific Post/Page IDs *( numerical )*. * @param int|str $hours Optional. A numeric expiration time for this link, in hours. Defaults to `72`. * @param bool $shrink Optional. Defaults to true. If false, the raw link will NOT be processed by the tinyURL API. * @return str|bool A Specific Post/Page Access Link, or false on failure. */ public static function sp_access_link_gen($sp_ids = FALSE, $hours = 72, $shrink = TRUE) { eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_before_sp_access_link_gen", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ if ((is_string($sp_ids) || is_numeric($sp_ids)) && ($sp_ids = preg_replace("/[^0-9;,]/", "", $sp_ids)) && ($leading_id = preg_replace("/^([0-9]+).*\$/", "\$1", $sp_ids)) && is_numeric($hours)) { $sp_access = c_ws_plugin__optimizemember_utils_encryption::encrypt("sp_time_hours:.:|:.:" . $sp_ids . ":.:|:.:" . strtotime("now") . ":.:|:.:" . $hours); /**/ $sp_access_link = add_query_arg("optimizemember_sp_access", urlencode($sp_access), get_permalink($leading_id)); /* Generate long URL/link. */ /**/ if ($shrink && ($shorter_url = c_ws_plugin__optimizemember_utils_urls::shorten($sp_access_link))) { $sp_access_link = $shorter_url . "#" . $_SERVER["HTTP_HOST"]; } } /**/ return apply_filters("ws_plugin__optimizemember_sp_access_link_gen", !empty($sp_access_link) ? $sp_access_link : false, get_defined_vars()); }
/** * Generates Registration Access Links. * * @package optimizeMember\Registrations * @since 3.5 * * @param str $subscr_gateway Payment Gateway associated with a Customer. * @param str $subscr_id Unique Subscr. ID associated with Payment Gateway; associated with a Customer. * @param str $custom Custom String value *( as supplied in Shortcode )*; must start with installation domain name. * @param int|str $item_number An optimizeMember-generated `item_number` *( i.e. `1` for Level 1, or `level|ccaps|fixed-term`, or `sp|ids|expiration` )*. * @param bool $shrink Optional. Defaults to true. If false, the raw registration link will NOT be reduced in size through the tinyURL API. * @return str|bool A Registration Access Link on success, else false on failure. */ public static function register_link_gen($subscr_gateway = FALSE, $subscr_id = FALSE, $custom = FALSE, $item_number = FALSE, $shrink = TRUE) { eval('foreach(array_keys(get_defined_vars())as$__v)$__refs[$__v]=&$$__v;'); do_action("ws_plugin__optimizemember_before_register_link_gen", get_defined_vars()); unset($__refs, $__v); /* Unset defined __refs, __v. */ /**/ if ($subscr_gateway && is_string($subscr_gateway) && $subscr_id && is_string($subscr_id) && $custom && is_string($custom) && $item_number && (is_string($item_number) || is_numeric($item_number))) { $register = c_ws_plugin__optimizemember_utils_encryption::encrypt("subscr_gateway_subscr_id_custom_item_number_time:.:|:.:" . $subscr_gateway . ":.:|:.:" . $subscr_id . ":.:|:.:" . $custom . ":.:|:.:" . $item_number . ":.:|:.:" . strtotime("now")); /**/ $register_link = site_url("/?optimizemember_register=" . urlencode($register)); /* Generate long URL/link. */ /**/ if ($shrink && ($shorter_url = c_ws_plugin__optimizemember_utils_urls::shorten($register_link))) { $register_link = $shorter_url . "#" . $_SERVER["HTTP_HOST"]; } } /**/ return apply_filters("ws_plugin__optimizemember_register_link_gen", !empty($register_link) ? $register_link : false, get_defined_vars()); }
function optimizemember_shorten_url($url = FALSE, $api_sp = FALSE, $try_backups = TRUE) { return c_ws_plugin__optimizemember_utils_urls::shorten($url, $api_sp, $try_backups); }
/** * Shortens a long URL, based on optimizeMember configuration. * * @package optimizeMember\Utilities * @since 111002 * * @param str $url A full/long URL to be shortened. * @param str $api_sp Optional. A specific URL shortening API to use. Defaults to that which is configured in the optimizeMember Dashboard. Normally `tiny_url`, by default. * @param bool $try_backups Defaults to true. If a failure occurs with the first API, we'll try others until we have success. * @return str|bool The shortened URL on success, else false on failure. */ public static function shorten($url = FALSE, $api_sp = FALSE, $try_backups = TRUE) { $url = $url && is_string($url) ? $url : false; $api_sp = $api_sp && is_string($api_sp) ? strtolower($api_sp) : false; /**/ $default_url_shortener = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["default_url_shortener"]; $default_custom_str_url_shortener = $GLOBALS["WS_PLUGIN__"]["optimizemember"]["o"]["default_custom_str_url_shortener"]; /**/ $apis = array("tiny_url", "goo_gl"); /**/ if ($url && ($api = $api_sp ? $api_sp : $default_url_shortener)) { if (!$api_sp && ($custom_url = trim(apply_filters("ws_plugin__optimizemember_url_shorten", false, get_defined_vars()))) && stripos($custom_url, "http") === 0) { return $shorter_url = $custom_url; } else { if (!$api_sp && stripos($default_custom_str_url_shortener, "http") === 0 && ($custom_url = trim(c_ws_plugin__optimizemember_utils_urls::remote(str_ireplace(array("%%s2_long_url%%", "%%s2_long_url_md5%%"), array(rawurlencode($url), urlencode(md5($url))), $default_custom_str_url_shortener)))) && stripos($custom_url, "http") === 0) { return $shorter_url = $custom_url; } else { if ($api === "tiny_url" && ($tiny_url = trim(c_ws_plugin__optimizemember_utils_urls::remote("http://tinyurl.com/api-create.php?url=" . rawurlencode($url)))) && stripos($tiny_url, "http") === 0) { return $shorter_url = $tiny_url; } else { if ($api === "goo_gl" && ($goo_gl = json_decode(trim(c_ws_plugin__optimizemember_utils_urls::remote("https://www.googleapis.com/urlshortener/v1/url" . (($goo_gl_key = apply_filters("ws_plugin__optimizemember_url_shorten_api_goo_gl_key", false)) ? "?key=" . urlencode($goo_gl_key) : ""), json_encode(array("longUrl" => $url)), array("headers" => array("Content-Type" => "application/json")))), true)) && !empty($goo_gl["id"]) && is_string($goo_gl_url = $goo_gl["id"]) && stripos($goo_gl_url, "http") === 0) { return $shorter_url = $goo_gl_url; } else { if ($try_backups && count($apis) > 1) { /**/ foreach (array_diff($apis, array($api)) as $backup) { if ($backup = c_ws_plugin__optimizemember_utils_urls::shorten($url, $backup, false)) { return $shorter_url = $backup; } } } } } } } } return false; }