本文整理汇总了PHP中rawurlencode_deep函数的典型用法代码示例。如果您正苦于以下问题:PHP rawurlencode_deep函数的具体用法?PHP rawurlencode_deep怎么用?PHP rawurlencode_deep使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rawurlencode_deep函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: jetpack_photon_url
/**
* Generates a Photon URL.
*
* @see http://developer.wordpress.com/docs/photon/
*
* @param string $image_url URL to the publicly accessible image you want to manipulate
* @param array|string $args An array of arguments, i.e. array( 'w' => '300', 'resize' => array( 123, 456 ) ), or in string form (w=123&h=456)
* @return string The raw final URL. You should run this through esc_url() before displaying it.
*/
function jetpack_photon_url($image_url, $args = array(), $scheme = null)
{
$image_url = trim($image_url);
$image_url = apply_filters('jetpack_photon_pre_image_url', $image_url, $args, $scheme);
$args = apply_filters('jetpack_photon_pre_args', $args, $image_url, $scheme);
if (empty($image_url)) {
return $image_url;
}
$image_url_parts = @parse_url($image_url);
// Unable to parse
if (!is_array($image_url_parts) || empty($image_url_parts['host']) || empty($image_url_parts['path'])) {
return $image_url;
}
if (is_array($args)) {
// Convert values that are arrays into strings
foreach ($args as $arg => $value) {
if (is_array($value)) {
$args[$arg] = implode(',', $value);
}
}
// Encode values
// See http://core.trac.wordpress.org/ticket/17923
$args = rawurlencode_deep($args);
}
// You can't run a Photon URL through Photon again because query strings are stripped.
// So if the image is already a Photon URL, append the new arguments to the existing URL.
if (in_array($image_url_parts['host'], array('i0.wp.com', 'i1.wp.com', 'i2.wp.com'))) {
$photon_url = add_query_arg($args, $image_url);
return jetpack_photon_url_scheme($photon_url, $scheme);
}
// This setting is Photon Server dependent
if (!apply_filters('jetpack_photon_any_extension_for_domain', false, $image_url_parts['host'])) {
// Photon doesn't support query strings so we ignore them and look only at the path.
// However some source images are served via PHP so check the no-query-string extension.
// For future proofing, this is a blacklist of common issues rather than a whitelist.
$extension = pathinfo($image_url_parts['path'], PATHINFO_EXTENSION);
if (empty($extension) || in_array($extension, array('php'))) {
return $image_url;
}
}
$image_host_path = $image_url_parts['host'] . $image_url_parts['path'];
// Figure out which CDN subdomain to use
srand(crc32($image_host_path));
$subdomain = rand(0, 2);
srand();
$photon_url = "http://i{$subdomain}.wp.com/{$image_host_path}";
// This setting is Photon Server dependent
if (isset($image_url_parts['query']) && apply_filters('jetpack_photon_add_query_string_to_domain', false, $image_url_parts['host'])) {
$photon_url .= '?q=' . rawurlencode($image_url_parts['query']);
}
if ($args) {
if (is_array($args)) {
$photon_url = add_query_arg($args, $photon_url);
} else {
// You can pass a query string for complicated requests but where you still want CDN subdomain help, etc.
$photon_url .= '?' . $args;
}
}
return jetpack_photon_url_scheme($photon_url, $scheme);
}
示例2: get_avatar_data
//.........这里部分代码省略.........
$args['found_avatar'] = false;
/**
* Filter whether to retrieve the avatar URL early.
*
* Passing a non-null value in the 'url' member of the return array will
* effectively short circuit get_avatar_data(), passing the value through
* the {@see 'get_avatar_data'} filter and returning early.
*
* @since 4.2.0
*
* @param array $args Arguments passed to get_avatar_data(), after processing.
* @param int|object|string $id_or_email A user ID, email address, or comment object.
*/
$args = apply_filters('pre_get_avatar_data', $args, $id_or_email);
if (isset($args['url']) && !is_null($args['url'])) {
/** This filter is documented in wp-includes/link-template.php */
return apply_filters('get_avatar_data', $args, $id_or_email);
}
$email_hash = '';
$user = $email = false;
// Process the user identifier.
if (is_numeric($id_or_email)) {
$user = get_user_by('id', absint($id_or_email));
} elseif (is_string($id_or_email)) {
if (strpos($id_or_email, '@md5.gravatar.com')) {
// md5 hash
list($email_hash) = explode('@', $id_or_email);
} else {
// email address
$email = $id_or_email;
}
} elseif ($id_or_email instanceof WP_User) {
// User Object
$user = $id_or_email;
} elseif ($id_or_email instanceof WP_Post) {
// Post Object
$user = get_user_by('id', (int) $id_or_email->post_author);
} elseif (is_object($id_or_email) && isset($id_or_email->comment_ID)) {
// Comment Object
/**
* Filter the list of allowed comment types for retrieving avatars.
*
* @since 3.0.0
*
* @param array $types An array of content types. Default only contains 'comment'.
*/
$allowed_comment_types = apply_filters('get_avatar_comment_types', array('comment'));
if (!empty($id_or_email->comment_type) && !in_array($id_or_email->comment_type, (array) $allowed_comment_types)) {
$args['url'] = false;
/** This filter is documented in wp-includes/link-template.php */
return apply_filters('get_avatar_data', $args, $id_or_email);
}
if (!empty($id_or_email->user_id)) {
$user = get_user_by('id', (int) $id_or_email->user_id);
}
if ((!$user || is_wp_error($user)) && !empty($id_or_email->comment_author_email)) {
$email = $id_or_email->comment_author_email;
}
}
if (!$email_hash) {
if ($user) {
$email = $user->user_email;
}
if ($email) {
$email_hash = md5(strtolower(trim($email)));
}
}
if ($email_hash) {
$args['found_avatar'] = true;
$gravatar_server = hexdec($email_hash[0]) % 3;
} else {
$gravatar_server = rand(0, 2);
}
$url_args = array('s' => $args['size'], 'd' => $args['default'], 'f' => $args['force_default'] ? 'y' : false, 'r' => $args['rating']);
if (is_ssl()) {
$url = 'https://secure.gravatar.com/avatar/' . $email_hash;
} else {
$url = sprintf('http://%d.gravatar.com/avatar/%s', $gravatar_server, $email_hash);
}
$url = add_query_arg(rawurlencode_deep(array_filter($url_args)), set_url_scheme($url, $args['scheme']));
/**
* Filter the avatar URL.
*
* @since 4.2.0
*
* @param string $url The URL of the avatar.
* @param int|object|string $id_or_email A user ID, email address, or comment object.
* @param array $args Arguments passed to get_avatar_data(), after processing.
*/
$args['url'] = apply_filters('get_avatar_url', $url, $id_or_email, $args);
/**
* Filter the avatar data.
*
* @since 4.2.0
*
* @param array $args Arguments passed to get_avatar_data(), after processing.
* @param int|object|string $id_or_email A user ID, email address, or comment object.
*/
return apply_filters('get_avatar_data', $args, $id_or_email);
}
示例3: bp_core_fetch_avatar
//.........这里部分代码省略.........
*
* @since 1.2.5
*
* @param string $avatar_url URL for a locally uploaded avatar.
* @param array $params Array of parameters for the request.
*/
return apply_filters('bp_core_fetch_avatar_url', $avatar_url, $params);
}
}
}
/**
* Filters whether or not to skip Gravatar check.
*
* @since 1.5.0
*
* @param bool $value Whether or not to skip Gravatar.
* @param array $params Array of parameters for the avatar request.
*/
if (!apply_filters('bp_core_fetch_avatar_no_grav', $params['no_grav'], $params)) {
// Set gravatar type
if (empty($bp->grav_default->{$params['object']})) {
$default_grav = 'wavatar';
} elseif ('mystery' == $bp->grav_default->{$params['object']}) {
/**
* Filters the Mystery person avatar src value.
*
* @since 1.2.0
*
* @param string $value Avatar value.
* @param string $value Width to display avatar at.
*/
$default_grav = apply_filters('bp_core_mysteryman_src', 'mm', $params['width']);
} else {
$default_grav = $bp->grav_default->{$params['object']};
}
// Set gravatar object
if (empty($params['email'])) {
if ('user' == $params['object']) {
$params['email'] = bp_core_get_user_email($params['item_id']);
} elseif ('group' == $params['object'] || 'blog' == $params['object']) {
$params['email'] = $params['item_id'] . '-' . $params['object'] . '@' . bp_get_root_domain();
}
}
/**
* Filters the Gravatar email to use.
*
* @since 1.1.0
*
* @param string $value Email to use in Gravatar request.
* @param string $value ID of the item being requested.
* @param string $value Object type being requested.
*/
$params['email'] = apply_filters('bp_core_gravatar_email', $params['email'], $params['item_id'], $params['object']);
/**
* Filters the Gravatar URL host.
*
* @since 1.0.2
*
* @param string $value Gravatar URL host.
*/
$gravatar = apply_filters('bp_gravatar_url', '//www.gravatar.com/avatar/');
// Append email hash to Gravatar
$gravatar .= md5(strtolower($params['email']));
// Main Gravatar URL args
$url_args = array('s' => $params['width']);
// Custom Gravatar URL args
if (!empty($params['force_default'])) {
$url_args['f'] = 'y';
}
if (!empty($params['rating'])) {
$url_args['r'] = strtolower($params['rating']);
}
// Only set default image if 'Gravatar Logo' is not requested
if ('gravatar_default' !== $default_grav) {
$url_args['d'] = $default_grav;
}
// Set up the Gravatar URL
$gravatar = esc_url(add_query_arg(rawurlencode_deep(array_filter($url_args)), $gravatar));
// No avatar was found, and we've been told not to use a gravatar.
} else {
/**
* Filters the avatar default when Gravatar is not used.
*
* This is a variable filter dependent on the avatar type being requested.
*
* @since 1.5.0
*
* @param string $value Default avatar for non-gravatar requests.
* @param array $params Array of parameters for the avatar request.
*/
$gravatar = apply_filters('bp_core_default_avatar_' . $params['object'], bp_core_avatar_default('local'), $params);
}
if (true === $params['html']) {
/** This filter is documented in bp-core/bp-core-avatars.php */
return apply_filters('bp_core_fetch_avatar', '<img src="' . $gravatar . '"' . $html_css_id . $html_class . $html_width . $html_height . $html_alt . $html_title . $extra_attr . ' />', $params, $params['item_id'], $params['avatar_dir'], $html_css_id, $html_width, $html_height, $avatar_folder_url, $avatar_folder_dir);
} else {
/** This filter is documented in bp-core/bp-core-avatars.php */
return apply_filters('bp_core_fetch_avatar_url', $gravatar, $params);
}
}
示例4: process_request
public function process_request($post, array $post_data)
{
$post_title = $this->get_share_title($post->ID);
$post_link = $this->get_share_url($post->ID);
if (function_exists('mb_stripos')) {
$strlen = 'mb_strlen';
$substr = 'mb_substr';
} else {
$strlen = 'strlen';
$substr = 'substr';
}
$via = $this->sharing_twitter_via($post);
$related = $this->get_related_accounts($post);
if ($via) {
$sig = " via @{$via}";
if ($related === $via) {
$related = false;
}
} else {
$via = false;
$sig = '';
}
$suffix_length = $this->short_url_length + $strlen($sig);
// $sig is handled by twitter in their 'via' argument.
// $post_link is handled by twitter in their 'url' argument.
if (140 < $strlen($post_title) + $suffix_length) {
// The -1 is for "\xE2\x80\xA6", a UTF-8 ellipsis.
$text = $substr($post_title, 0, 140 - $suffix_length - 1) . "…";
} else {
$text = $post_title;
}
// Record stats
parent::process_request($post, $post_data);
$url = $post_link;
$twitter_url = add_query_arg(rawurlencode_deep(array_filter(compact('via', 'related', 'text', 'url'))), 'https://twitter.com/intent/tweet');
// Redirect to Twitter
wp_redirect($twitter_url);
die;
}
示例5: redirect_canonical
//.........这里部分代码省略.........
}
$redirect['path'] = user_trailingslashit(preg_replace('|/' . preg_quote($wp_rewrite->index, '|') . '/?$|', '/', $redirect['path']));
// strip off trailing /index.php/
if (!empty($addl_path) && $wp_rewrite->using_index_permalinks() && strpos($redirect['path'], '/' . $wp_rewrite->index . '/') === false) {
$redirect['path'] = trailingslashit($redirect['path']) . $wp_rewrite->index . '/';
}
if (!empty($addl_path)) {
$redirect['path'] = trailingslashit($redirect['path']) . $addl_path;
}
$redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path'];
}
if ('wp-register.php' == basename($redirect['path'])) {
if (is_multisite()) {
/** This filter is documented in wp-login.php */
$redirect_url = apply_filters('wp_signup_location', network_site_url('wp-signup.php'));
} else {
$redirect_url = wp_registration_url();
}
wp_redirect($redirect_url, 301);
die;
}
}
// tack on any additional query vars
$redirect['query'] = preg_replace('#^\\??&*?#', '', $redirect['query']);
if ($redirect_url && !empty($redirect['query'])) {
parse_str($redirect['query'], $_parsed_query);
$redirect = @parse_url($redirect_url);
if (!empty($_parsed_query['name']) && !empty($redirect['query'])) {
parse_str($redirect['query'], $_parsed_redirect_query);
if (empty($_parsed_redirect_query['name'])) {
unset($_parsed_query['name']);
}
}
$_parsed_query = rawurlencode_deep($_parsed_query);
$redirect_url = add_query_arg($_parsed_query, $redirect_url);
}
if ($redirect_url) {
$redirect = @parse_url($redirect_url);
}
// www.example.com vs example.com
$user_home = @parse_url(home_url());
if (!empty($user_home['host'])) {
$redirect['host'] = $user_home['host'];
}
if (empty($user_home['path'])) {
$user_home['path'] = '/';
}
// Handle ports
if (!empty($user_home['port'])) {
$redirect['port'] = $user_home['port'];
} else {
unset($redirect['port']);
}
// trailing /index.php
$redirect['path'] = preg_replace('|/' . preg_quote($wp_rewrite->index, '|') . '/*?$|', '/', $redirect['path']);
// Remove trailing spaces from the path
$redirect['path'] = preg_replace('#(%20| )+$#', '', $redirect['path']);
if (!empty($redirect['query'])) {
// Remove trailing spaces from certain terminating query string args
$redirect['query'] = preg_replace('#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query']);
// Clean up empty query strings
$redirect['query'] = trim(preg_replace('#(^|&)(p|page_id|cat|tag)=?(&|$)#', '&', $redirect['query']), '&');
// Redirect obsolete feeds
$redirect['query'] = preg_replace('#(^|&)feed=rss(&|$)#', '$1feed=rss2$2', $redirect['query']);
// Remove redundant leading ampersands
$redirect['query'] = preg_replace('#^\\??&*?#', '', $redirect['query']);
示例6: jetpack_photon_url
/**
* Generates a Photon URL.
*
* @see http://developer.wordpress.com/docs/photon/
*
* @param string $image_url URL to the publicly accessible image you want to manipulate
* @param array|string $args An array of arguments, i.e. array( 'w' => '300', 'resize' => array( 123, 456 ) ), or in string form (w=123&h=456)
* @return string The raw final URL. You should run this through esc_url() before displaying it.
*/
function jetpack_photon_url($image_url, $args = array(), $scheme = null)
{
$image_url = trim($image_url);
if (class_exists('Jetpack')) {
/**
* Disables Photon URL processing for local development
*
* @module photon
*
* @since 4.1.0
*
* @param bool false Result of Jetpack::is_development_mode.
*/
if (true === apply_filters('jetpack_photon_development_mode', Jetpack::is_development_mode())) {
return $image_url;
}
}
/**
* Allow specific image URls to avoid going through Photon.
*
* @module photon
*
* @since 3.2.0
*
* @param bool false Should the image be returned as is, without going through Photon. Default to false.
* @param string $image_url Image URL.
* @param array|string $args Array of Photon arguments.
* @param string|null $scheme Image scheme. Default to null.
*/
if (false !== apply_filters('jetpack_photon_skip_for_url', false, $image_url, $args, $scheme)) {
return $image_url;
}
/**
* Filter the original image URL before it goes through Photon.
*
* @module photon
*
* @since 1.9.0
*
* @param string $image_url Image URL.
* @param array|string $args Array of Photon arguments.
* @param string|null $scheme Image scheme. Default to null.
*/
$image_url = apply_filters('jetpack_photon_pre_image_url', $image_url, $args, $scheme);
/**
* Filter the original Photon image parameters before Photon is applied to an image.
*
* @module photon
*
* @since 1.9.0
*
* @param array|string $args Array of Photon arguments.
* @param string $image_url Image URL.
* @param string|null $scheme Image scheme. Default to null.
*/
$args = apply_filters('jetpack_photon_pre_args', $args, $image_url, $scheme);
if (empty($image_url)) {
return $image_url;
}
$image_url_parts = @parse_url($image_url);
// Unable to parse
if (!is_array($image_url_parts) || empty($image_url_parts['host']) || empty($image_url_parts['path'])) {
return $image_url;
}
if (is_array($args)) {
// Convert values that are arrays into strings
foreach ($args as $arg => $value) {
if (is_array($value)) {
$args[$arg] = implode(',', $value);
}
}
// Encode values
// See http://core.trac.wordpress.org/ticket/17923
$args = rawurlencode_deep($args);
}
/** This filter is documented below. */
$custom_photon_url = apply_filters('jetpack_photon_domain', '', $image_url);
$custom_photon_url = esc_url($custom_photon_url);
// You can't run a Photon URL through Photon again because query strings are stripped.
// So if the image is already a Photon URL, append the new arguments to the existing URL.
if (in_array($image_url_parts['host'], array('i0.wp.com', 'i1.wp.com', 'i2.wp.com')) || $image_url_parts['host'] === parse_url($custom_photon_url, PHP_URL_HOST)) {
$photon_url = add_query_arg($args, $image_url);
return jetpack_photon_url_scheme($photon_url, $scheme);
}
/**
* Allow Photon to use query strings as well.
* By default, Photon doesn't support query strings so we ignore them and look only at the path.
* This setting is Photon Server dependent.
*
* @module photon
*
//.........这里部分代码省略.........
示例7: redirect_canonical
//.........这里部分代码省略.........
}
$redirect['path'] = user_trailingslashit( preg_replace('|/index.php/?$|', '/', $redirect['path']) ); // strip off trailing /index.php/
if ( !empty( $addl_path ) && $wp_rewrite->using_index_permalinks() && strpos($redirect['path'], '/index.php/') === false )
$redirect['path'] = trailingslashit($redirect['path']) . 'index.php/';
if ( !empty( $addl_path ) )
$redirect['path'] = trailingslashit($redirect['path']) . $addl_path;
$redirect_url = $redirect['scheme'] . '://' . $redirect['host'] . $redirect['path'];
}
if ( 'wp-register.php' == basename( $redirect['path'] ) ) {
if ( is_multisite() )
$redirect_url = apply_filters( 'wp_signup_location', site_url( 'wp-signup.php' ) );
else
$redirect_url = site_url( 'wp-login.php?action=register' );
wp_redirect( $redirect_url, 301 );
die();
}
}
// tack on any additional query vars
$redirect['query'] = preg_replace( '#^\??&*?#', '', $redirect['query'] );
if ( $redirect_url && !empty($redirect['query']) ) {
parse_str( $redirect['query'], $_parsed_query );
$redirect = @parse_url($redirect_url);
if ( ! empty( $_parsed_query['name'] ) && ! empty( $redirect['query'] ) ) {
parse_str( $redirect['query'], $_parsed_redirect_query );
if ( empty( $_parsed_redirect_query['name'] ) )
unset( $_parsed_query['name'] );
}
$_parsed_query = rawurlencode_deep( $_parsed_query );
$redirect_url = add_query_arg( $_parsed_query, $redirect_url );
}
if ( $redirect_url )
$redirect = @parse_url($redirect_url);
// www.example.com vs example.com
$user_home = @parse_url(home_url());
if ( !empty($user_home['host']) )
$redirect['host'] = $user_home['host'];
if ( empty($user_home['path']) )
$user_home['path'] = '/';
// Handle ports
if ( !empty($user_home['port']) )
$redirect['port'] = $user_home['port'];
else
unset($redirect['port']);
// trailing /index.php
$redirect['path'] = preg_replace('|/index.php/*?$|', '/', $redirect['path']);
// Remove trailing spaces from the path
$redirect['path'] = preg_replace( '#(%20| )+$#', '', $redirect['path'] );
if ( !empty( $redirect['query'] ) ) {
// Remove trailing spaces from certain terminating query string args
$redirect['query'] = preg_replace( '#((p|page_id|cat|tag)=[^&]*?)(%20| )+$#', '$1', $redirect['query'] );
// Clean up empty query strings
$redirect['query'] = trim(preg_replace( '#(^|&)(p|page_id|cat|tag)=?(&|$)#', '&', $redirect['query']), '&');
示例8: sanitize_input
//.........这里部分代码省略.........
* @uses https://developer.wordpress.org/reference/functions/rawurlencode_deep
* @uses class-mcb-admin.php Mobile_Contact_Bar_Admin::sanitize_hex_color()
* @uses class-mcb-admin.php Mobile_Contact_Bar_Admin::sanitize_rgba_color()
* @uses class-mcb-admin.php Mobile_Contact_Bar_Admin::sanitize_float()
* @uses class-mcb-admin.php Mobile_Contact_Bar_Admin::sanitize_phone_number()
* @uses class-mcb-admin.php Mobile_Contact_Bar_Admin::sanitize_keys_recursive()
*
*/
public static function sanitize_input($input)
{
$in_settings = $input['settings'];
$in_contacts = $input['contacts'];
$out_settings = array();
$out_contacts = array();
/* -------------------------------------------------------------------------- */
/* Settings */
/* -------------------------------------------------------------------------- */
// workaround empty checkboxes
$in_settings = array_replace(array_map(function ($field) {
if ('checkbox' == $field['type']) {
return 0;
}
}, self::$settings), $in_settings);
// all settings will be saved, at least with their default values
$in_settings = array_replace(array_map(function ($field) {
return $field['default'];
}, self::$settings), $in_settings);
foreach ($in_settings as $id => $value) {
switch (self::$settings[$id]['type']) {
case 'select':
if (in_array($value, array_keys(self::$settings[$id]['options']))) {
$out_settings[$id] = sanitize_text_field($value);
} else {
$out_settings[$id] = sanitize_text_field(self::$settings[$id]['default']);
}
break;
case 'color-picker':
$color = self::sanitize_hex_color($value);
if (!$color) {
$color = self::sanitize_rgba_color($value);
}
if (!$color) {
$color = self::sanitize_hex_color(self::$settings[$id]['default']);
}
$out_settings[$id] = $color;
break;
case 'checkbox':
case 'number':
$out_settings[$id] = absint($value);
break;
case 'slider':
$float = self::sanitize_float($value);
$out_settings[$id] = $float ? $float : self::sanitize_float(self::$settings[$id]['default']);
break;
}
}
/* -------------------------------------------------------------------------- */
/* Contacts */
/* -------------------------------------------------------------------------- */
foreach ($in_contacts as $id => $contact) {
$resource = '';
switch (self::$contacts[$id]['protocol']) {
case 'tel':
$resource = self::sanitize_phone_number($contact['url']);
break;
case 'skype':
$resource = sanitize_text_field($contact['url']);
break;
case 'mailto':
$resource = sanitize_email($contact['url']);
$resource = is_email($resource) ? $resource : '';
break;
case 'http':
case 'https':
$resource = esc_url_raw($contact['url']);
break;
default:
$resource = sanitize_text_field($contact['url']);
break;
}
if (!empty($resource)) {
$out_contacts[$id] = array('icon' => sanitize_key(self::$contacts[$id]['icon']), 'protocol' => sanitize_key(self::$contacts[$id]['protocol']), 'resource' => $resource);
}
if (isset(self::$contacts[$id]['parameters'])) {
$in_parameters = array_filter(array_intersect_key($contact, self::$contacts[$id]['parameters']));
$out_parameters = rawurlencode_deep($in_parameters);
if (array_filter($out_parameters)) {
$out_contacts[$id]['parameters'] = array_filter($out_parameters);
}
}
}
// two sublists: first one is for contacts with icon, second one is for contacts without icons but with parameters
$displayable = array_filter($out_contacts, function ($contact) {
return isset($contact['icon']);
});
$storable = array_diff_key($out_contacts, $displayable);
// contacts with parameters only
$out_contacts = array_merge($displayable, $storable);
return array_filter(array_replace(self::$option, array('settings' => self::sanitize_keys_recursive($out_settings), 'contacts' => array_filter($out_contacts) ? self::sanitize_keys_recursive(array_filter($out_contacts)) : null)));
}
示例9: bp_core_fetch_avatar_filter_check
public function bp_core_fetch_avatar_filter_check($html, $params)
{
// Check that the passed parameters match the original custom parameters.
$this->assertEmpty(array_merge(array_diff($params, $this->params), array_diff($this->params, $params)));
// Check the returned html to see that it matches an expected value.
// Get the correct default avatar, based on whether gravatars are allowed.
if ($params['no_grav']) {
$avatar_url = bp_core_avatar_default('local', $params);
} else {
// This test has the slight odor of hokum since it recreates so much code that could be changed at any time.
$bp = buddypress();
$host = '//www.gravatar.com/avatar/';
// Set expected gravatar type
if (empty($bp->grav_default->{$this->params['object']})) {
$default_grav = 'wavatar';
} elseif ('mystery' == $bp->grav_default->{$this->params['object']}) {
$default_grav = apply_filters('bp_core_mysteryman_src', 'mm', $this->params['width']);
} else {
$default_grav = $bp->grav_default->{$this->params['object']};
}
$avatar_url = $host . md5(strtolower($this->params['email']));
// Main Gravatar URL args.
$url_args = array('s' => $this->params['width']);
// Force default.
if (!empty($this->params['force_default'])) {
$url_args['f'] = 'y';
}
// Gravatar rating; http://bit.ly/89QxZA
$rating = strtolower(get_option('avatar_rating'));
if (!empty($rating)) {
$url_args['r'] = $rating;
}
// Default avatar.
if ('gravatar_default' !== $default_grav) {
$url_args['d'] = $default_grav;
}
// Set up the Gravatar URL.
$avatar_url = esc_url(add_query_arg(rawurlencode_deep(array_filter($url_args)), $avatar_url));
}
$expected_html = '<img src="' . $avatar_url . '" id="' . $this->params['css_id'] . '" class="' . $this->params['class'] . ' ' . $this->params['object'] . '-' . $this->params['item_id'] . '-avatar avatar-' . $this->params['width'] . ' photo" width="' . $this->params['width'] . '" height="' . $this->params['height'] . '" alt="' . $this->params['alt'] . '" title="' . $this->params['title'] . '" ' . $this->params['extra_attr'] . ' />';
$this->assertEquals($html, $expected_html);
}
示例10: redirect_canonical
/**
* Manages canonical redirection of the homepage when using page on front
*
* @since 0.1
*
* @param string $redirect_url
* @param string $requested_url
* @return bool|string modified url, false if redirection is canceled
*/
public function redirect_canonical($redirect_url, $requested_url)
{
global $wp_query;
if (is_page() && !is_feed() && isset($wp_query->queried_object) && $wp_query->queried_object->ID == $this->curlang->page_on_front) {
$url = is_paged() ? $this->links_model->add_paged_to_link($this->links->get_home_url(), $wp_query->query_vars['page']) : $this->links->get_home_url();
// Don't forget additional query vars
$query = parse_url($redirect_url, PHP_URL_QUERY);
if (!empty($query)) {
parse_str($query, $query_vars);
$query_vars = rawurlencode_deep($query_vars);
// WP encodes query vars values
$url = add_query_arg($query_vars, $url);
}
return $url;
}
return $redirect_url;
}
示例11: image_resize
//.........这里部分代码省略.........
$_max_w = get_option('medium_size_w');
$_max_h = get_option('medium_size_h');
if (!$_max_w && !$_max_h) {
$_max_w = 300;
$_max_h = 300;
}
} elseif ('large' == $size) {
$_max_w = get_option('large_size_w');
$_max_h = get_option('large_size_h');
} elseif (is_array($size)) {
$_max_w = $w = $size[0];
$_max_h = $h = $size[1];
} elseif (!empty($_wp_additional_image_sizes[$size])) {
$_max_w = $w = $_wp_additional_image_sizes[$size]['width'];
$_max_h = $h = $_wp_additional_image_sizes[$size]['height'];
$crop = $_wp_additional_image_sizes[$size]['crop'];
} elseif ($content_width > 0) {
$_max_w = $content_width;
$_max_h = 0;
} else {
$_max_w = 1024;
$_max_h = 0;
}
// Constrain default image sizes to the theme's content width, if available.
if ($content_width > 0 && in_array($size, array('thumbnail', 'medium', 'large'))) {
$_max_w = min($_max_w, $content_width);
}
$resized = false;
$img_url = wp_get_attachment_url($id);
/**
* Filter the original image Photon-compatible parameters before changes are
*
* @param array|string $args Array of Photon-compatible arguments.
* @param string $image_url Image URL.
*/
$args = apply_filters('vip_go_image_resize_pre_args', $args, $image_url);
if (!$crop) {
$imagedata = wp_get_attachment_metadata($id);
if (!empty($imagedata['width']) || !empty($imagedata['height'])) {
$h = $imagedata['height'];
$w = $imagedata['width'];
list($w, $h) = wp_constrain_dimensions($w, $h, $_max_w, $_max_h);
if ($w < $imagedata['width'] || $h < $imagedata['height']) {
$resized = true;
}
} else {
$w = $_max_w;
$h = $_max_h;
}
}
if ($crop) {
$constrain = false;
$imagedata = wp_get_attachment_metadata($id);
if ($imagedata) {
$w = $imagedata['width'];
$h = $imagedata['height'];
}
if (empty($w)) {
$w = $_max_w;
}
if (empty($h)) {
$h = $_max_h;
}
// If the image width is bigger than the allowed max, scale it to match
if ($w >= $_max_w) {
$w = $_max_w;
} else {
$constrain = true;
}
// If the image height is bigger than the allowed max, scale it to match
if ($h >= $_max_h) {
$h = $_max_h;
} else {
$constrain = true;
}
if ($constrain) {
list($w, $h) = wp_constrain_dimensions($w, $h, $_max_w, $_max_h);
}
$args['w'] = $w;
$args['h'] = $h;
$args['crop'] = '1';
$resized = true;
} elseif ('full' != $size) {
$args['w'] = $w;
$resized = true;
}
if (is_array($args)) {
// Convert values that are arrays into strings
foreach ($args as $arg => $value) {
if (is_array($value)) {
$args[$arg] = implode(',', $value);
}
}
// Encode values
// See http://core.trac.wordpress.org/ticket/17923
$args = rawurlencode_deep($args);
}
$img_url = add_query_arg($args, $img_url);
return array($img_url, $w, $h, $resized);
}