! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } } ! \is_string( $url ) || $url === '' ) { return $url; } if ( $this->is_relative( $url ) === true ) { return $this->build_absolute_url( $url ); } return $url; } /** * Parse the home URL setting to find the base URL for relative URLs. * * @param string|null $path Optional path string. * * @return string */ public function build_absolute_url( $path = null ) { $path = \wp_parse_url( $path, \PHP_URL_PATH ); $url_parts = \wp_parse_url( \home_url() ); $base_url = \trailingslashit( $url_parts['scheme'] . '://' . $url_parts['host'] ); if ( ! \is_null( $path ) ) { $base_url .= \ltrim( $path, '/' ); } return $base_url; } /** * Returns the link type. * * @param array $url The URL, as parsed by wp_parse_url. * @param array|null $home_url Optional. The home URL, as parsed by wp_parse_url. Used to avoid reparsing the home_url. * @param bool $is_image Whether or not the link is an image. * * @return string The link type. */ public function get_link_type( $url, $home_url = null, $is_image = false ) { // If there is no scheme and no host the link is always internal. // Beware, checking just the scheme isn't enough as a link can be //yoast.com for instance. if ( empty( $url['scheme'] ) && empty( $url['host'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // If there is a scheme but it's not http(s) then the link is always external. if ( \array_key_exists( 'scheme', $url ) && ! \in_array( $url['scheme'], [ 'http', 'https' ], true ) ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } if ( \is_null( $home_url ) ) { $home_url = \wp_parse_url( \home_url() ); } // When the base host is equal to the host. if ( isset( $url['host'] ) && $url['host'] !== $home_url['host'] ) { return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } // There is no base path and thus all URLs of the same domain are internal. if ( empty( $home_url['path'] ) ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } // When there is a path and it matches the start of the url. if ( isset( $url['path'] ) && \strpos( $url['path'], $home_url['path'] ) === 0 ) { return ( $is_image ) ? SEO_Links::TYPE_INTERNAL_IMAGE : SEO_Links::TYPE_INTERNAL; } return ( $is_image ) ? SEO_Links::TYPE_EXTERNAL_IMAGE : SEO_Links::TYPE_EXTERNAL; } /** * Recreate current URL. * * @param bool $with_request_uri Whether we want the REQUEST_URI appended. * * @return string */ public function recreate_current_url( $with_request_uri = true ) { $current_url = 'http'; if ( isset( $_SERVER['HTTPS'] ) && $_SERVER['HTTPS'] === 'on' ) { $current_url .= 's'; } $current_url .= '://'; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $suffix = ( $with_request_uri && isset( $_SERVER['REQUEST_URI'] ) ) ? $_SERVER['REQUEST_URI'] : ''; if ( isset( $_SERVER['SERVER_NAME'] ) && ! empty( $_SERVER['SERVER_NAME'] ) ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_name = $_SERVER['SERVER_NAME']; } else { // Early return with just the path. return $suffix; } $server_port = ''; if ( isset( $_SERVER['SERVER_PORT'] ) && $_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443' ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $server_port = $_SERVER['SERVER_PORT']; } if ( ! empty( $server_port ) ) { $current_url .= $server_name . ':' . $server_port . $suffix; } else { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput -- We know this is scary. $current_url .= $server_name . $suffix; } return $current_url; } /** * Parses a URL and returns its components, this wrapper function was created to support unit tests. * * @param string $parsed_url The URL to parse. * @return array The parsed components of the URL. */ public function parse_str_params( $parsed_url ) { $array = []; // @todo parse_str changes spaces in param names into `_`, we should find a better way to support them. \wp_parse_str( $parsed_url, $array ); return $array; } }
Fatal error: Uncaught Error: Class "Yoast\WP\SEO\Helpers\Url_Helper" not found in /htdocs/wp-content/plugins/wordpress-seo/src/generated/container.php:1556 Stack trace: #0 /htdocs/wp-content/plugins/wordpress-seo/src/generated/container.php(1475): Yoast\WP\SEO\Generated\Cached_Container->getIndexableHomePageBuilderService() #1 /htdocs/wp-content/plugins/wordpress-seo/src/generated/container.php(5074): Yoast\WP\SEO\Generated\Cached_Container->getIndexableBuilderService() #2 /htdocs/wp-content/plugins/wordpress-seo/vendor_prefixed/symfony/dependency-injection/Container.php(271): Yoast\WP\SEO\Generated\Cached_Container->getIndexableRepositoryService() #3 /htdocs/wp-content/plugins/wordpress-seo/src/surfaces/classes-surface.php(38): YoastSEO_Vendor\Symfony\Component\DependencyInjection\Container->get('Yoast\\WP\\SEO\\Re...') #4 /htdocs/wp-content/plugins/wordpress-seo/inc/class-wpseo-admin-bar-menu.php(131): Yoast\WP\SEO\Surfaces\Classes_Surface->get('Yoast\\WP\\SEO\\Re...') #5 /htdocs/wp-content/plugins/wordpress-seo/inc/wpseo-non-ajax-functions.php(20): WPSEO_Admin_Bar_Menu->__construct() #6 /htdocs/wp-includes/class-wp-hook.php(310): wpseo_initialize_admin_bar('') #7 /htdocs/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters(NULL, Array) #8 /htdocs/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #9 /htdocs/wp-settings.php(654): do_action('wp_loaded') #10 /htdocs/wp-config.php(96): require_once('/htdocs/wp-sett...') #11 /htdocs/wp-load.php(50): require_once('/htdocs/wp-conf...') #12 /htdocs/wp-blog-header.php(13): require_once('/htdocs/wp-load...') #13 /htdocs/index.php(17): require('/htdocs/wp-blog...') #14 {main} thrown in /htdocs/wp-content/plugins/wordpress-seo/src/generated/container.php on line 1556