Jetpack_Sitemap_Finder

The Jetpack_Sitemap_Finder object deals with constructing sitemap URIs.

Defined (1)

The class is defined in the following location(s).

/modules/sitemaps/sitemap-finder.php  
  1. class Jetpack_Sitemap_Finder { 
  2.  
  3. /** 
  4. * Construct the complete URL of a sitemap file. Depends on 
  5. * permalink settings. 
  6. * @access public 
  7. * @since 4.8.0 
  8. * @since 4.8.1 Call jetpack_sitemap_uri() 
  9. * @param string $filename The filename of the sitemap. 
  10. * @return string Complete URI of the given sitemap file. 
  11. */ 
  12. public function construct_sitemap_url( $filename ) { 
  13. return jetpack_sitemap_uri( $filename ); 
  14.  
  15. /** 
  16. * Path and query prefix of sitemap files. Depends on permalink 
  17. * settings. 
  18. * @access public 
  19. * @since 4.8.0 
  20. * @return string The path+query prefix. 
  21. */ 
  22. public function the_jetpack_sitemap_path_and_query_prefix() { 
  23. global $wp_rewrite; 
  24.  
  25. // Get path fragment from home_url(). 
  26. $home = wp_parse_url( home_url() ); 
  27. if ( isset( $home['path'] ) ) { 
  28. $home_path = $home['path']; 
  29. } else { 
  30. $home_path = ''; 
  31.  
  32. // Get additional path fragment from filter. 
  33. $location = Jetpack_Options::get_option_and_ensure_autoload( 
  34. 'jetpack_sitemap_location',  
  35. '' 
  36. ); 
  37.  
  38. if ( $wp_rewrite->using_index_permalinks() ) { 
  39. return $home_path . '/index.php' . $location . '/'; 
  40. } elseif ( $wp_rewrite->using_permalinks() ) { 
  41. return $home_path . $location . '/'; 
  42. } else { 
  43. return $home_path . $location . '/?jetpack-sitemap='; 
  44.  
  45. /** 
  46. * Examine a path+query URI fragment looking for a sitemap request. 
  47. * @access public 
  48. * @since 4.8.0 
  49. * @param string $raw_uri A URI (path+query only) to test for sitemap-ness. 
  50. * @return array @args { 
  51. * @type string $sitemap_name The recognized sitemap name (or null). 
  52. * } 
  53. */ 
  54. public function recognize_sitemap_uri( $raw_uri ) { 
  55. // The path+query where sitemaps are served. 
  56. $sitemap_path = $this->the_jetpack_sitemap_path_and_query_prefix(); 
  57.  
  58. // A regex which detects $sitemap_path at the beginning of a string. 
  59. $path_regex = '/^' . preg_quote( $sitemap_path, '/' ) . '/'; 
  60.  
  61. // Check that the request URI begins with the sitemap path. 
  62. if ( preg_match( $path_regex, $raw_uri ) ) { 
  63. // Strip off the $sitemap_path and any trailing slash. 
  64. $stripped_uri = preg_replace( $path_regex, '', rtrim( $raw_uri, '/' ) ); 
  65. } else { 
  66. $stripped_uri = ''; 
  67.  
  68. // Check that the stripped uri begins with one of the sitemap prefixes. 
  69. if ( preg_match( '/^sitemap|^image-s|^news-s|^video-s/', $stripped_uri ) ) { 
  70. $filename = $stripped_uri; 
  71. } else { 
  72. $filename = null; 
  73.  
  74. return array( 
  75. 'sitemap_name' => $filename,  
  76. ); 
  77.