xml.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?= '<'.'?'.'xml version="1.0" encoding="UTF-8"?>'."\n" ?>
  2. <?php if (null != $style) {
  3. echo '<'.'?'.'xml-stylesheet href="'.$style.'" type="text/xsl"?>'."\n";
  4. } ?>
  5. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
  6. <?php foreach ($items as $item) : ?>
  7. <url>
  8. <loc><?= $item['loc'] ?></loc>
  9. <?php
  10. if (! empty($item['translations'])) {
  11. foreach ($item['translations'] as $translation) {
  12. echo "\t\t".'<xhtml:link rel="alternate" hreflang="'.$translation['language'].'" href="'.$translation['url'].'" />'."\n";
  13. }
  14. }
  15. if (! empty($item['alternates'])) {
  16. foreach ($item['alternates'] as $alternate) {
  17. echo "\t\t".'<xhtml:link rel="alternate" media="'.$alternate['media'].'" href="'.$alternate['url'].'" />'."\n";
  18. }
  19. }
  20. if ($item['priority'] !== null) {
  21. echo "\t\t".'<priority>'.$item['priority'].'</priority>'."\n";
  22. }
  23. if ($item['lastmod'] !== null) {
  24. echo "\t\t".'<lastmod>'.date('Y-m-d\TH:i:sP', strtotime($item['lastmod'])).'</lastmod>'."\n";
  25. }
  26. if ($item['freq'] !== null) {
  27. echo "\t\t".'<changefreq>'.$item['freq'].'</changefreq>'."\n";
  28. }
  29. if (! empty($item['images'])) {
  30. foreach ($item['images'] as $image) {
  31. echo "\t\t".'<image:image>'."\n";
  32. echo "\t\t\t".'<image:loc>'.$image['url'].'</image:loc>'."\n";
  33. if (isset($image['title'])) {
  34. echo "\t\t\t".'<image:title>'.$image['title'].'</image:title>'."\n";
  35. }
  36. if (isset($image['caption'])) {
  37. echo "\t\t\t".'<image:caption>'.$image['caption'].'</image:caption>'."\n";
  38. }
  39. if (isset($image['geo_location'])) {
  40. echo "\t\t\t".'<image:geo_location>'.$image['geo_location'].'</image:geo_location>'."\n";
  41. }
  42. if (isset($image['license'])) {
  43. echo "\t\t\t".'<image:license>'.$image['license'].'</image:license>'."\n";
  44. }
  45. echo "\t\t".'</image:image>'."\n";
  46. }
  47. }
  48. if (! empty($item['videos'])) {
  49. foreach ($item['videos'] as $video) {
  50. echo "\t\t".'<video:video>'."\n";
  51. if (isset($video['thumbnail_loc'])) {
  52. echo "\t\t\t".'<video:thumbnail_loc>'.$video['thumbnail_loc'].'</video:thumbnail_loc>'."\n";
  53. }
  54. if (isset($video['title'])) {
  55. echo "\t\t\t".'<video:title><![CDATA['.$video['title'].']]></video:title>'."\n";
  56. }
  57. if (isset($video['description'])) {
  58. echo "\t\t\t".'<video:description><![CDATA['.$video['description'].']]></video:description>'."\n";
  59. }
  60. if (isset($video['content_loc'])) {
  61. echo "\t\t\t".'<video:content_loc>'.$video['content_loc'].'</video:content_loc>'."\n";
  62. }
  63. if (isset($video['duration'])) {
  64. echo "\t\t\t".'<video:duration>'.$video['duration'].'</video:duration>'."\n";
  65. }
  66. if (isset($video['expiration_date'])) {
  67. echo "\t\t\t".'<video:expiration_date>'.$video['expiration_date'].'</video:expiration_date>'."\n";
  68. }
  69. if (isset($video['rating'])) {
  70. echo "\t\t\t".'<video:rating>'.$video['rating'].'</video:rating>'."\n";
  71. }
  72. if (isset($video['view_count'])) {
  73. echo "\t\t\t".'<video:view_count>'.$video['view_count'].'</video:view_count>'."\n";
  74. }
  75. if (isset($video['publication_date'])) {
  76. echo "\t\t\t".'<video:publication_date>'.$video['publication_date'].'</video:publication_date>'."\n";
  77. }
  78. if (isset($video['family_friendly'])) {
  79. echo "\t\t\t".'<video:family_friendly>'.$video['family_friendly'].'</video:family_friendly>'."\n";
  80. }
  81. if (isset($video['requires_subscription'])) {
  82. echo "\t\t\t".'<video:requires_subscription>'.$video['requires_subscription'].'</video:requires_subscription>'."\n";
  83. }
  84. if (isset($video['live'])) {
  85. echo "\t\t\t".'<video:live>'.$video['live'].'</video:live>'."\n";
  86. }
  87. if (isset($video['player_loc'])) {
  88. echo "\t\t\t".'<video:player_loc allow_embed="'.$video['player_loc']['allow_embed'].'" autoplay="'.
  89. $video['player_loc']['autoplay'].'">'.$video['player_loc']['player_loc'].'</video:player_loc>'."\n";
  90. }
  91. if (isset($video['restriction'])) {
  92. echo "\t\t\t".'<video:restriction relationship="'.$video['restriction']['relationship'].'">'.$video['restriction']['restriction'].'</video:restriction>'."\n";
  93. }
  94. if (isset($video['gallery_loc'])) {
  95. echo "\t\t\t".'<video:gallery_loc title="'.$video['gallery_loc']['title'].'">'.$video['gallery_loc']['gallery_loc'].'</video:gallery_loc>'."\n";
  96. }
  97. if (isset($video['price'])) {
  98. echo "\t\t\t".'<video:price currency="'.$video['price']['currency'].'">'.$video['price']['price'].'</video:price>'."\n";
  99. }
  100. if (isset($video['uploader'])) {
  101. echo "\t\t\t".'<video:uploader info="'.$video['uploader']['info'].'">'.$video['uploader']['uploader'].'</video:uploader>'."\n";
  102. }
  103. echo "\t\t".'</video:video>'."\n";
  104. }
  105. }
  106. ?>
  107. </url>
  108. <?php endforeach; ?>
  109. </urlset>