PluginProbe
Yatra – Travel Booking & Tour Operator Software / trunk
Yatra – Travel Booking & Tour Operator Software vtrunk
3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 2.0.11 All 82 releases
yatra / app / Sitemap / Integrations / CoreProvider.php

CoreProvider.php in Yatra – Travel Booking & Tour Operator Software trunk, at app/Sitemap/Integrations/CoreProvider.php

73 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Sitemap\Integrations;
6
7 use Yatra\Sitemap\SitemapService;
8
9 /**
10 * Feeds Yatra URLs into WordPress core sitemaps (wp-sitemap.xml), used when no
11 * third-party SEO plugin has taken over sitemap generation. Flat provider (no
12 * subtypes): all Yatra URLs appear under a single wp-sitemap-yatra-N.xml,
13 * mirroring the consolidated /yatra-sitemap.xml.
14 *
15 * Only referenced after WP_Sitemaps_Provider is confirmed loaded (see
16 * SitemapManager), so extending the core class is safe.
17 */
18 class CoreProvider extends \WP_Sitemaps_Provider
19 {
20 private SitemapService $service;
21
22 public function __construct(SitemapService $service)
23 {
24 $this->service = $service;
25 $this->name = 'yatra';
26 $this->object_type = 'yatra';
27 }
28
29 /**
30 * @param int $page_number
31 * @param string $object_subtype
32 * @return array<int, array{loc: string, lastmod: string}>
33 */
34 public function get_url_list($page_number, $object_subtype = ''): array
35 {
36 $entries = $this->service->getAllEntries();
37
38 $perPage = $this->maxUrls();
39 $offset = ((int) $page_number - 1) * $perPage;
40
41 $list = [];
42 foreach (array_slice($entries, $offset, $perPage) as $entry) {
43 // Core's renderer reads 'loc'; lastmod is surfaced only if a site
44 // opts in via the wp_sitemaps_index_entry filter.
45 $list[] = ['loc' => $entry['loc'], 'lastmod' => $entry['lastmod']];
46 }
47
48 return $list;
49 }
50
51 /**
52 * @param string $object_subtype
53 */
54 public function get_max_num_pages($object_subtype = ''): int
55 {
56 $count = $this->service->getCount();
57 if ($count === 0) {
58 return 0;
59 }
60
61 return (int) ceil($count / $this->maxUrls());
62 }
63
64 private function maxUrls(): int
65 {
66 $max = function_exists('wp_sitemaps_get_max_urls')
67 ? (int) wp_sitemaps_get_max_urls($this->object_type)
68 : 2000;
69
70 return $max > 0 ? $max : 2000;
71 }
72 }
73