discover_pingback_server_uri()
最后更新于:2021-11-26 01:53:20
discover_pingback_server_uri( string$url, string$deprecated=”)Finds a pingback server URI based on the given URL.
参数
- $url
-
(string) (Required) URL to ping.
- $deprecated
-
(string) (Optional) Not Used.
Default value: ”
响应
(string|false) String containing URI on success, false on failure.
源文件
文件: gc-includes/comment.php
function discover_pingback_server_uri( $url, $deprecated = '' ) {
if ( ! empty( $deprecated ) ) {
_deprecated_argument( __FUNCTION__, '2.7.0' );
}
$pingback_str_dquote = 'rel="pingback"';
$pingback_str_squote = 'rel='pingback'';
/** @todo Should use Filter Extension or custom preg_match instead. */
$parsed_url = parse_url( $url );
if ( ! isset( $parsed_url['host'] ) ) { // Not a URL. This should never happen.
return false;
}
// Do not search for a pingback server on our own uploads.
$uploads_dir = gc_get_upload_dir();
if ( 0 === strpos( $url, $uploads_dir['baseurl'] ) ) {
return false;
}
$response = gc_safe_remote_head(
$url,
array(
'timeout' => 2,
'httpversion' => '1.0',
)
);
if ( is_gc_error( $response ) ) {
return false;
}
if ( gc_remote_retrieve_header( $response, 'x-pingback' ) ) {
return gc_remote_retrieve_header( $response, 'x-pingback' );
}
// Not an (x)html, sgml, or xml page, no use going further.
if ( preg_match( '#(image|audio|video|model)/#is', gc_remote_retrieve_header( $response, 'content-type' ) ) ) {
return false;
}
// Now do a GET since we're going to look in the HTML headers (and we're sure it's not a binary file).
$response = gc_safe_remote_get(
$url,
array(
'timeout' => 2,
'httpversion' => '1.0',
)
);
if ( is_gc_error( $response ) ) {
return false;
}
$contents = gc_remote_retrieve_body( $response );
$pingback_link_offset_dquote = strpos( $contents, $pingback_str_dquote );
$pingback_link_offset_squote = strpos( $contents, $pingback_str_squote );
if ( $pingback_link_offset_dquote || $pingback_link_offset_squote ) {
$quote = ( $pingback_link_offset_dquote ) ? '"' : ''';
$pingback_link_offset = ( '"' === $quote ) ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
$pingback_href_pos = strpos( $contents, 'href='https://docs.gechiui.com/functions/discover_pingback_server_uri/, $pingback_link_offset );___$pingback_href_start = $pingback_href_pos + 6;___$pingback_href_end = strpos( $contents, $quote, $pingback_href_start );___$pingback_server_url_len = $pingback_href_end - $pingback_href_start;___$pingback_server_url = substr( $contents, $pingback_href_start, $pingback_server_url_len );____/ We may find rel="pingback" but an incomplete pingback URL.
if ( $pingback_server_url_len > 0 ) { // We got it!
return $pingback_server_url;
}
}
return false;
}