本文整理匯總了PHP中c_ws_plugin__s2member_utils_urls::shorten方法的典型用法代碼示例。如果您正苦於以下問題:PHP c_ws_plugin__s2member_utils_urls::shorten方法的具體用法?PHP c_ws_plugin__s2member_utils_urls::shorten怎麽用?PHP c_ws_plugin__s2member_utils_urls::shorten使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類c_ws_plugin__s2member_utils_urls
的用法示例。
在下文中一共展示了c_ws_plugin__s2member_utils_urls::shorten方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: register_link_gen
/**
* Generates Registration Access Links.
*
* @package s2Member\Registrations
* @since 3.5
*
* @param string $subscr_gateway Payment Gateway associated with a Customer.
* @param string $subscr_id Unique Subscr. ID associated with Payment Gateway; associated with a Customer.
* @param string $custom Custom String value *(as supplied in Shortcode)*; must start with installation domain name.
* @param int|string $item_number An s2Member-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 string|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)
{
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action("ws_plugin__s2member_before_register_link_gen", get_defined_vars());
unset($__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__s2member_utils_encryption::encrypt("subscr_gateway_subscr_id_custom_item_number_time:.:|:.:" . $subscr_gateway . ":.:|:.:" . $subscr_id . ":.:|:.:" . $custom . ":.:|:.:" . $item_number . ":.:|:.:" . strtotime("now"));
$register_link = site_url("/?s2member_register=" . urlencode($register));
// Generate long URL/link.
if ($shrink && ($shorter_url = c_ws_plugin__s2member_utils_urls::shorten($register_link))) {
$register_link = $shorter_url . "#" . $_SERVER["HTTP_HOST"];
}
}
return apply_filters("ws_plugin__s2member_register_link_gen", !empty($register_link) ? $register_link : false, get_defined_vars());
}
示例2: sp_access_link_gen
/**
* Generates Specific Post/Page Access links.
*
* @package s2Member\SP_Access
* @since 3.5
*
* @param string|int $sp_ids Comma-delimited list of Specific Post/Page IDs *(numerical)*.
* @param int|string $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)
{
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action("ws_plugin__s2member_before_sp_access_link_gen", get_defined_vars());
unset($__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__s2member_utils_encryption::encrypt("sp_time_hours:.:|:.:" . $sp_ids . ":.:|:.:" . strtotime("now") . ":.:|:.:" . $hours);
$sp_access_link = add_query_arg("s2member_sp_access", urlencode($sp_access), get_permalink($leading_id));
// Generate long URL/link.
if ($shrink && ($shorter_url = c_ws_plugin__s2member_utils_urls::shorten($sp_access_link))) {
$sp_access_link = $shorter_url . "#" . $_SERVER["HTTP_HOST"];
}
}
return apply_filters("ws_plugin__s2member_sp_access_link_gen", !empty($sp_access_link) ? $sp_access_link : false, get_defined_vars());
}
示例3: register_link_gen
/**
* Generates Registration Access Links.
*
* @package s2Member\Registrations
* @since 3.5
*
* @param string $subscr_gateway Payment Gateway associated with a Customer.
* @param string $subscr_id Unique Subscr. ID associated with Payment Gateway; associated with a Customer.
* @param string $custom Custom String value *(as supplied in Shortcode)*; must start with installation domain name.
* @param int|string $item_number An s2Member-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 string|bool A Registration Access Link on success, else false on failure.
*/
public static function register_link_gen($subscr_gateway = '', $subscr_id = '', $custom = '', $item_number = '', $shrink = TRUE)
{
foreach (array_keys(get_defined_vars()) as $__v) {
$__refs[$__v] =& ${$__v};
}
do_action('ws_plugin__s2member_before_register_link_gen', get_defined_vars());
unset($__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__s2member_utils_encryption::encrypt('subscr_gateway_subscr_id_custom_item_number_time:.:|:.:' . $subscr_gateway . ':.:|:.:' . $subscr_id . ':.:|:.:' . $custom . ':.:|:.:' . $item_number . ':.:|:.:' . strtotime('now'));
$register_link = home_url('/?s2member_register=' . urlencode($register));
// Generate long URL/link.
if ($shrink && ($shorter_url = c_ws_plugin__s2member_utils_urls::shorten($register_link))) {
$register_link = $shorter_url . '#' . $_SERVER['HTTP_HOST'];
}
}
return apply_filters('ws_plugin__s2member_register_link_gen', !empty($register_link) ? $register_link : FALSE, get_defined_vars());
}
示例4: shorten
/**
* Shortens a long URL, based on s2Member configuration.
*
* @package s2Member\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 s2Member 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__"]["s2member"]["o"]["default_url_shortener"];
$default_custom_str_url_shortener = $GLOBALS["WS_PLUGIN__"]["s2member"]["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__s2member_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__s2member_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__s2member_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__s2member_utils_urls::remote("https://www.googleapis.com/urlshortener/v1/url" . (($goo_gl_key = apply_filters("ws_plugin__s2member_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__s2member_utils_urls::shorten($url, $backup, false)) {
return $shorter_url = $backup;
}
}
}
}
}
}
}
}
return false;
}
示例5: s2member_shorten_url
function s2member_shorten_url($url = FALSE, $api_sp = FALSE, $try_backups = TRUE)
{
return c_ws_plugin__s2member_utils_urls::shorten($url, $api_sp, $try_backups);
}