Advertisement
NicholasB

sitemap-xsl.php

Apr 27th, 2023
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.92 KB | None | 0 0
  1. <?php
  2. /**
  3. * Sitemap Video stylesheet.
  4. *
  5. * @package RankMath
  6. * @subpackage RankMath\Sitemap
  7. */
  8.  
  9. use RankMath\Helper;
  10. use RankMath\Sitemap\Router;
  11.  
  12. defined( 'ABSPATH' ) || exit;
  13.  
  14. // Echo so opening tag doesn't get confused for PHP.
  15. echo '<?xml version="1.0" encoding="UTF-8"?>';
  16. ?>
  17. <xsl:stylesheet version="2.0"
  18. xmlns:html="http://www.w3.org/TR/REC-html40"
  19. xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
  20. xmlns:video="http://www.google.com/schemas/sitemap-video/1.1"
  21. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  22. <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
  23.  
  24. <xsl:template match="/">
  25. <html>
  26. <head>
  27. <title><?php echo esc_html( $title ); ?></title>
  28. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  29. <style type="text/css">
  30. body {
  31. font-size: 14px;
  32. font-family: -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Oxygen-Sans,Ubuntu,Cantarell,"Helvetica Neue",sans-serif;
  33. margin: 0;
  34. color: #545353;
  35. }
  36. a {
  37. color: #05809e;
  38. text-decoration: none;
  39. }
  40. h1 {
  41. font-size: 24px;
  42. font-family: Verdana,Geneva,sans-serif;
  43. font-weight: normal;
  44. margin: 0;
  45. }
  46.  
  47. #description {
  48. background-color: #4275f4;
  49. padding: 20px 40px;
  50. color: #fff;
  51. padding: 30px 30px 20px;
  52. }
  53. #description h1,
  54. #description p,
  55. #description a {
  56. color: #fff;
  57. margin: 0;
  58. font-size: 1.1em;
  59. }
  60. #description h1 {
  61. font-size: 2em;
  62. margin-bottom: 1em;
  63. }
  64. #description p {
  65. margin-top: 5px;
  66. }
  67.  
  68. #content {
  69. padding: 20px 30px;
  70. background: #fff;
  71. max-width: 75%;
  72. margin: 0 auto;
  73. }
  74.  
  75. table {
  76. border: none;
  77. border-collapse: collapse;
  78. font-size: .9em;
  79. width: 100%;
  80. }
  81. th {
  82. background-color: #4275f4;
  83. color: #fff;
  84. text-align: left;
  85. padding: 15px;
  86. font-size: 14px;
  87. cursor: pointer;
  88. }
  89. td {
  90. padding: 10px;
  91. border-bottom: 1px solid #ddd;
  92. }
  93. tbody tr:nth-child(even) {
  94. background-color: #f7f7f7;
  95. }
  96. table td a {
  97. display: block;
  98. }
  99. </style>
  100. </head>
  101. <body>
  102. <div id="description">
  103. <h1><?php esc_html_e( 'Video Sitemap', 'rank-math-pro' ); ?></h1>
  104. <?php if ( false === $this->do_filter( 'sitemap/remove_credit', false ) ) : ?>
  105. <p>
  106. <?php
  107. printf(
  108. wp_kses_post(
  109. /* translators: link to rankmath.com */
  110. __( 'This Video Sitemap is generated by <a href="%s" target="_blank">Rank Math WordPress SEO Plugin</a>. It is what search engines like Google use to find and understand the video content on your website.', 'rank-math-pro' )
  111. ),
  112. 'https://s.rankmath.com/home'
  113. );
  114. ?>
  115. </p>
  116. <?php endif; ?>
  117.  
  118. <p>
  119. <?php
  120. printf(
  121. wp_kses_post(
  122. /* translators: link to rankmath.com */
  123. __( 'Learn more about <a href="%s" target="_blank">Video Sitemap</a>.', 'rank-math-pro' )
  124. ),
  125. 'https://developers.google.com/search/docs/advanced/sitemaps/video-sitemaps'
  126. );
  127. ?>
  128. </p>
  129. </div>
  130. <div id="content">
  131. <p>
  132. <?php
  133. printf(
  134. /* translators: xsl value count */
  135. __( 'This XML Sitemap contains <strong>%s</strong> URLs.', 'rank-math-pro' ),
  136. '<xsl:value-of select="count(sitemap:urlset/sitemap:url/video:video)"/>'
  137. );
  138. ?>
  139. </p>
  140. <p class="expl">
  141. <?php
  142. printf(
  143. /* translators: Sitemap index link. */
  144. __( '<a href="%s">&#8592; Sitemap Index</a>', 'rank-math-pro' ),
  145. esc_url( Router::get_base_url( 'sitemap_index.xml' ) )
  146. );
  147. ?>
  148. </p>
  149. <table id="sitemap" cellpadding="3">
  150. <thead>
  151. <tr>
  152. <th width="15%"><?php echo esc_html__( 'Video', 'rank-math-pro' ); ?></th>
  153. <th width="20%"><?php echo esc_html__( 'Title', 'rank-math-pro' ); ?></th>
  154. <th width="20%"><?php echo esc_html__( 'Description', 'rank-math-pro' ); ?></th>
  155. <th width="15%"><?php echo esc_html__( 'Tags', 'rank-math-pro' ); ?></th>
  156. <th width="15%"><?php echo esc_html__( 'Last Mod.', 'rank-math-pro' ); ?></th>
  157. </tr>
  158. </thead>
  159. <tbody>
  160. <xsl:for-each select="sitemap:urlset/sitemap:url">
  161. <xsl:for-each select="video:video">
  162. <tr>
  163. <td>
  164. <xsl:variable name="thumbURL">
  165. <xsl:value-of select="video:thumbnail_loc"/>
  166. </xsl:variable>
  167.  
  168. <xsl:variable name="flvURL">
  169. <xsl:value-of select="video:player_loc"/>
  170. </xsl:variable>
  171.  
  172. <a href="{$flvURL}">
  173. <xsl:choose>
  174. <xsl:when test="$thumbURL != ''">
  175. <img src="{$thumbURL}" width="80" height="60" />
  176. </xsl:when>
  177. <xsl:otherwise>
  178. -
  179. </xsl:otherwise>
  180. </xsl:choose>
  181. </a>
  182. </td>
  183. <td>
  184. <xsl:variable name="itemURL">
  185. <xsl:value-of select="../sitemap:loc"/>
  186. </xsl:variable>
  187. <a href="{$itemURL}">
  188. <xsl:value-of select="video:title"/>
  189. </a>
  190. </td>
  191. <td>
  192. <xsl:variable name="desc">
  193. <xsl:value-of select="video:description"/>
  194. </xsl:variable>
  195. <xsl:choose>
  196. <xsl:when test="string-length($desc) &lt; 200">
  197. <xsl:value-of select="$desc"/>
  198. </xsl:when>
  199. <xsl:otherwise>
  200. <xsl:value-of select="concat(substring($desc,1,200),' ...')"/>
  201. </xsl:otherwise>
  202. </xsl:choose>
  203. </td>
  204. <td>
  205. <xsl:for-each select="video:tag">
  206. <xsl:value-of select="."/>,
  207. </xsl:for-each>
  208. </td>
  209. <td>
  210. <xsl:value-of select="concat(substring(video:modification_date,0,11),concat(' ', substring(video:modification_date,12,5)),concat(' ', substring(video:modification_date,20,6)))"/>
  211. </td>
  212. </tr>
  213. </xsl:for-each>
  214. </xsl:for-each>
  215. </tbody>
  216. </table>
  217. </div>
  218. </body>
  219. </html>
  220. </xsl:template>
  221.  
  222. </xsl:stylesheet>
  223.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement