| @@ -30,11 +30,23 @@ | ||
| 30 | 30 | * @since 4.8.0 Remove 1000 post limit. |
| 31 | 31 | * @author Automattic |
| 32 | 32 | */ |
| 33 | 33 | |
| 34 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 35 | + exit( 0 ); | |
| 36 | +} | |
| 37 | + | |
| 34 | 38 | /* Include all of the sitemap subclasses. */ |
| 35 | 39 | require_once __DIR__ . '/sitemap-constants.php'; |
| 36 | 40 | require_once __DIR__ . '/sitemap-buffer.php'; |
| 41 | +require_once __DIR__ . '/sitemap-buffer-fallback.php'; | |
| 42 | +require_once __DIR__ . '/sitemap-buffer-xmlwriter.php'; | |
| 43 | +require_once __DIR__ . '/sitemap-buffer-page-xmlwriter.php'; | |
| 44 | +require_once __DIR__ . '/sitemap-buffer-image-xmlwriter.php'; | |
| 45 | +require_once __DIR__ . '/sitemap-buffer-video-xmlwriter.php'; | |
| 46 | +require_once __DIR__ . '/sitemap-buffer-news-xmlwriter.php'; | |
| 47 | +require_once __DIR__ . '/sitemap-buffer-master-xmlwriter.php'; | |
| 48 | +require_once __DIR__ . '/sitemap-buffer-factory.php'; | |
| 37 | 49 | require_once __DIR__ . '/sitemap-stylist.php'; |
| 38 | 50 | require_once __DIR__ . '/sitemap-librarian.php'; |
| 39 | 51 | require_once __DIR__ . '/sitemap-finder.php'; |
| 40 | 52 | require_once __DIR__ . '/sitemap-builder.php'; |
| @@ -48,8 +60,10 @@ | ||
| 48 | 60 | /** |
| 49 | 61 | * Governs the generation, storage, and serving of sitemaps. |
| 50 | 62 | * |
| 51 | 63 | * @since 4.8.0 |
| 64 | + * | |
| 65 | + * @phan-constructor-used-for-side-effects | |
| 52 | 66 | */ |
| 53 | 67 | class Jetpack_Sitemap_Manager { |
| 54 | 68 | |
| 55 | 69 | /** |
| @@ -174,9 +188,9 @@ | ||
| 174 | 188 | } |
| 175 | 189 | |
| 176 | 190 | echo $the_content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- All content created by Jetpack. |
| 177 | 191 | |
| 178 | - die(); | |
| 192 | + die( 0 ); | |
| 179 | 193 | } |
| 180 | 194 | |
| 181 | 195 | /** |
| 182 | 196 | * Callback to intercept sitemap url requests and serve sitemap files. |
| @@ -186,21 +200,14 @@ | ||
| 186 | 200 | */ |
| 187 | 201 | public function callback_action_catch_sitemap_urls() { |
| 188 | 202 | // Regular expressions for sitemap URL routing. |
| 189 | 203 | $regex = array( |
| 190 | - 'master' => '/^sitemap\.xml$/', | |
| 191 | - 'sitemap' => '/^sitemap-[1-9][0-9]*\.xml$/', | |
| 192 | - 'index' => '/^sitemap-index-[1-9][0-9]*\.xml$/', | |
| 193 | - 'sitemap-style' => '/^sitemap\.xsl$/', | |
| 194 | - 'index-style' => '/^sitemap-index\.xsl$/', | |
| 195 | - 'image' => '/^image-sitemap-[1-9][0-9]*\.xml$/', | |
| 196 | - 'image-index' => '/^image-sitemap-index-[1-9][0-9]*\.xml$/', | |
| 197 | - 'image-style' => '/^image-sitemap\.xsl$/', | |
| 198 | - 'video' => '/^video-sitemap-[1-9][0-9]*\.xml$/', | |
| 199 | - 'video-index' => '/^video-sitemap-index-[1-9][0-9]*\.xml$/', | |
| 200 | - 'video-style' => '/^video-sitemap\.xsl$/', | |
| 201 | - 'news' => '/^news-sitemap\.xml$/', | |
| 202 | - 'news-style' => '/^news-sitemap\.xsl$/', | |
| 204 | + 'sitemap' => '/^sitemap-[1-9][0-9]*\.xml$/', | |
| 205 | + 'index' => '/^sitemap-index-[1-9][0-9]*\.xml$/', | |
| 206 | + 'image' => '/^image-sitemap-[1-9][0-9]*\.xml$/', | |
| 207 | + 'image-index' => '/^image-sitemap-index-[1-9][0-9]*\.xml$/', | |
| 208 | + 'video' => '/^video-sitemap-[1-9][0-9]*\.xml$/', | |
| 209 | + 'video-index' => '/^video-sitemap-index-[1-9][0-9]*\.xml$/', | |
| 203 | 210 | ); |
| 204 | 211 | |
| 205 | 212 | // The raw path(+query) of the requested URI. |
| 206 | 213 | if ( isset( $_SERVER['REQUEST_URI'] ) ) { // WPCS: Input var okay. |
| @@ -226,9 +233,9 @@ | ||
| 226 | 233 | */ |
| 227 | 234 | $xml_content_type = apply_filters( 'jetpack_sitemap_content_type', 'text/xml' ); |
| 228 | 235 | |
| 229 | 236 | // Catch master sitemap xml. |
| 230 | - if ( preg_match( $regex['master'], $request['sitemap_name'] ) ) { | |
| 237 | + if ( 'sitemap.xml' === $request['sitemap_name'] ) { | |
| 231 | 238 | $sitemap_content = $this->librarian->get_sitemap_text( |
| 232 | 239 | jp_sitemap_filename( JP_MASTER_SITEMAP_TYPE, 0 ), |
| 233 | 240 | JP_MASTER_SITEMAP_TYPE |
| 234 | 241 | ); |
| @@ -244,8 +251,57 @@ | ||
| 244 | 251 | $sitemap_content |
| 245 | 252 | ); |
| 246 | 253 | } |
| 247 | 254 | |
| 255 | + // Catch sitemap xsl. | |
| 256 | + if ( 'sitemap.xsl' === $request['sitemap_name'] ) { | |
| 257 | + $this->serve_raw_and_die( | |
| 258 | + 'application/xml', | |
| 259 | + Jetpack_Sitemap_Stylist::sitemap_xsl() | |
| 260 | + ); | |
| 261 | + } | |
| 262 | + | |
| 263 | + // Catch sitemap index xsl. | |
| 264 | + if ( 'sitemap-index.xsl' === $request['sitemap_name'] ) { | |
| 265 | + $this->serve_raw_and_die( | |
| 266 | + 'application/xml', | |
| 267 | + Jetpack_Sitemap_Stylist::sitemap_index_xsl() | |
| 268 | + ); | |
| 269 | + } | |
| 270 | + | |
| 271 | + // Catch image sitemap xsl. | |
| 272 | + if ( 'image-sitemap.xsl' === $request['sitemap_name'] ) { | |
| 273 | + $this->serve_raw_and_die( | |
| 274 | + 'application/xml', | |
| 275 | + Jetpack_Sitemap_Stylist::image_sitemap_xsl() | |
| 276 | + ); | |
| 277 | + } | |
| 278 | + | |
| 279 | + // Catch video sitemap xsl. | |
| 280 | + if ( 'video-sitemap.xsl' === $request['sitemap_name'] ) { | |
| 281 | + $this->serve_raw_and_die( | |
| 282 | + 'application/xml', | |
| 283 | + Jetpack_Sitemap_Stylist::video_sitemap_xsl() | |
| 284 | + ); | |
| 285 | + } | |
| 286 | + | |
| 287 | + // Catch news sitemap xml. | |
| 288 | + if ( 'news-sitemap.xml' === $request['sitemap_name'] ) { | |
| 289 | + $sitemap_builder = new Jetpack_Sitemap_Builder(); | |
| 290 | + $this->serve_raw_and_die( | |
| 291 | + $xml_content_type, | |
| 292 | + $sitemap_builder->news_sitemap_xml() | |
| 293 | + ); | |
| 294 | + } | |
| 295 | + | |
| 296 | + // Catch news sitemap xsl. | |
| 297 | + if ( 'news-sitemap.xsl' === $request['sitemap_name'] ) { | |
| 298 | + $this->serve_raw_and_die( | |
| 299 | + 'application/xml', | |
| 300 | + Jetpack_Sitemap_Stylist::news_sitemap_xsl() | |
| 301 | + ); | |
| 302 | + } | |
| 303 | + | |
| 248 | 304 | // Catch sitemap xml. |
| 249 | 305 | if ( preg_match( $regex['sitemap'], $request['sitemap_name'] ) ) { |
| 250 | 306 | $this->serve_raw_and_die( |
| 251 | 307 | $xml_content_type, |
| @@ -266,24 +322,8 @@ | ||
| 266 | 322 | ) |
| 267 | 323 | ); |
| 268 | 324 | } |
| 269 | 325 | |
| 270 | - // Catch sitemap xsl. | |
| 271 | - if ( preg_match( $regex['sitemap-style'], $request['sitemap_name'] ) ) { | |
| 272 | - $this->serve_raw_and_die( | |
| 273 | - 'application/xml', | |
| 274 | - Jetpack_Sitemap_Stylist::sitemap_xsl() | |
| 275 | - ); | |
| 276 | - } | |
| 277 | - | |
| 278 | - // Catch sitemap index xsl. | |
| 279 | - if ( preg_match( $regex['index-style'], $request['sitemap_name'] ) ) { | |
| 280 | - $this->serve_raw_and_die( | |
| 281 | - 'application/xml', | |
| 282 | - Jetpack_Sitemap_Stylist::sitemap_index_xsl() | |
| 283 | - ); | |
| 284 | - } | |
| 285 | - | |
| 286 | 326 | // Catch image sitemap xml. |
| 287 | 327 | if ( preg_match( $regex['image'], $request['sitemap_name'] ) ) { |
| 288 | 328 | $this->serve_raw_and_die( |
| 289 | 329 | $xml_content_type, |
| @@ -304,16 +344,8 @@ | ||
| 304 | 344 | ) |
| 305 | 345 | ); |
| 306 | 346 | } |
| 307 | 347 | |
| 308 | - // Catch image sitemap xsl. | |
| 309 | - if ( preg_match( $regex['image-style'], $request['sitemap_name'] ) ) { | |
| 310 | - $this->serve_raw_and_die( | |
| 311 | - 'application/xml', | |
| 312 | - Jetpack_Sitemap_Stylist::image_sitemap_xsl() | |
| 313 | - ); | |
| 314 | - } | |
| 315 | - | |
| 316 | 348 | // Catch video sitemap xml. |
| 317 | 349 | if ( preg_match( $regex['video'], $request['sitemap_name'] ) ) { |
| 318 | 350 | $this->serve_raw_and_die( |
| 319 | 351 | $xml_content_type, |
| @@ -333,33 +365,8 @@ | ||
| 333 | 365 | JP_VIDEO_SITEMAP_INDEX_TYPE |
| 334 | 366 | ) |
| 335 | 367 | ); |
| 336 | 368 | } |
| 337 | - | |
| 338 | - // Catch video sitemap xsl. | |
| 339 | - if ( preg_match( $regex['video-style'], $request['sitemap_name'] ) ) { | |
| 340 | - $this->serve_raw_and_die( | |
| 341 | - 'application/xml', | |
| 342 | - Jetpack_Sitemap_Stylist::video_sitemap_xsl() | |
| 343 | - ); | |
| 344 | - } | |
| 345 | - | |
| 346 | - // Catch news sitemap xml. | |
| 347 | - if ( preg_match( $regex['news'], $request['sitemap_name'] ) ) { | |
| 348 | - $sitemap_builder = new Jetpack_Sitemap_Builder(); | |
| 349 | - $this->serve_raw_and_die( | |
| 350 | - $xml_content_type, | |
| 351 | - $sitemap_builder->news_sitemap_xml() | |
| 352 | - ); | |
| 353 | - } | |
| 354 | - | |
| 355 | - // Catch news sitemap xsl. | |
| 356 | - if ( preg_match( $regex['news-style'], $request['sitemap_name'] ) ) { | |
| 357 | - $this->serve_raw_and_die( | |
| 358 | - 'application/xml', | |
| 359 | - Jetpack_Sitemap_Stylist::news_sitemap_xsl() | |
| 360 | - ); | |
| 361 | - } | |
| 362 | 369 | } |
| 363 | 370 | } |
| 364 | 371 | |
| 365 | 372 | /** |
| @@ -599,4 +606,8 @@ | ||
| 599 | 606 | * @param string $sitemap_url Sitemap URL. |
| 600 | 607 | */ |
| 601 | 608 | return apply_filters( 'jetpack_sitemap_location', $sitemap_url ); |
| 602 | 609 | } |
| 610 | + | |
| 611 | +// Register Jetpack Sitemaps abilities (WordPress Abilities API, WP 6.9+). | |
| 612 | +require_once __DIR__ . '/abilities/class-sitemaps-abilities.php'; | |
| 613 | +\Automattic\Jetpack\Plugin\Abilities\Sitemaps_Abilities::init(); | |